Can I disable rewrite for specific directory? - regex

I have a website that runs with cakePHP, and i have an aplication in www/application_test that does not work using the rewrite rule.
There is a method to disable the rule for directories within www/application_test?
Follows my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(app|cake|vendors)/(.*)$ app/webroot/$1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
<IfModule mod_ssl.c>
#Include conf/ssl.conf
</IfModule>

Ad this line just below RewriteEngine On line
# ignore application_test for any rewrites
RewriteRule ^application_test(/|$) - [NC,L]

Related

How to redirect everything but an specific path on a htaccess file?

I'm trying to create an htaccess file so that everything gets redirected to the root of the site except for an specific path /api/date.
I have this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I've made some research on javascript regex and it seems that it is not possible to exclude words. So it is possible to do this here? How?
Thanks!
Try with below we are excluding /api/date and passing everything apart from that.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!(\/api\/date)$).+$ /index.php [L]
</IfModule>

Htacces rewriterule not working with two joker characters

RewriteRule ^(.*)data(.*)$ http://regi.krater.hu/$1data$2 [R=301,L]
It should make http://krater.hu/xxxxdataxxxx.php -> http://regi.krater.hu/xxxxdataxxxxx.php
I still don't understand where is my error? Thak you for the help! :)
Full code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)data(.*)$ http://regi.krater.hu/$1data$2 [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
From your example it appears that you are entering data in QUERY_STRING not in URI. Use this rule instead:
RewriteCond %{THE_REQUEST} \s/+(.*?)data(\S*)\s [NC]
RewriteRule ^ http://regi.krater.hu/%1data%2 [R=302,L,NE]

htaccess URL rewrite - requested URL not found on server

Need to hide one folder while loading like Uniimart1609/S/page.php to Uniimart1609/page.php
in linux
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule Home_Page.php$ S/Home_Page.php
</IfModule>
is redirected http://Uniimart1609/Home_Page.php this is working fine, but when i rewrite the htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /S/$1.php [L,NC,QSA]
</IfModule>
getting The requested URL /S/Home_Page.php was not found on this server. Pleas help
Have your rule like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /Uniimart1609/
RewriteCond %{THE_REQUEST} /S/(\S*) [NC]
RewriteRule ^ %1? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/S/$1\.php -f [NC]
RewriteRule ^([^./]+)/?$ S/$1.php [L]
</IfModule>

htaccess regex wordpress not working

I have a wordpress site set up with some custom redirect rules set up. The weird thing is I am sure these all of these were working before but now some of them no longer function.
Here is the complete htaccess file:
RewriteRule ^properties/([a-zA-Z]+)/([a-zA-Z\+\'.]+) /properties/?prov=$1&city=$2&%{QUERY_STRING} [R,NC]
RewriteRule ^properties/([0-9]+) /properties/?id=$1 [R,NC]
RewriteRule ^([0-9][0-9][0-9][0-9][0-9])$ /properties/?id=$1 [R,NC]
RewriteRule ^expand.php?id=([0-9]+) /properties/?id=$1 [R,NC]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
right now the only rule that actually works (other than the directory change for wordpress itself) is
RewriteRule ^([0-9][0-9][0-9][0-9][0-9])$ /properties/?id=$1 [R,NC]
I've tried throwing in simple rules to test, like
RewriteRule ^/bob /contact [R,NC]
but that doesn't work either
* Edit the below issue was fixed and is definitely not related to the issue above (but I'll leave it here in case there was a comment that referenced it)*
Also, not sure if this gives any insight but on the page where the redirect actually works, my wordpress theme is broken, the wp_footer never fires and the rest of the page fails
Have it like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^bob/?$ /about [R,NC,L]
RewriteRule ^properties/([a-zA-Z]+)/([a-zA-Z+'.]+)/?$ /properties/?prov=$1&city=$2 [R,NC,QSA,L]
RewriteRule ^(?:properties/)?([0-9]+)/?$ /properties/?id=$1 [R,QSA,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
There are a couple of possible causes... You aren't enabling mod_rewrite until after your RewriteRules, the custom rules should be included inside their own <IfModule mod_rewrite.c> tag with RewriteEngine on preceding them, and you probably want to set RewriteBase to whatever the root of your site is (perhaps /wordpress subdirectory? you may want to include what you would like these rules to rewrite to and from.) You cannot match on a querystring within a RewriteRule either, you have to use a RewriteCond.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^properties/([a-zA-Z]+)/([a-zA-Z\+\'.]+) /properties/?prov=$1&city=$2&%{QUERY_STRING} [R,NC]
RewriteRule ^properties/([0-9]+) /properties/?id=$1 [R,NC]
RewriteRule ^([0-9]{5,5})$ /properties/?id=$1 [R,NC]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
Also updated ^([0-9][0-9][0-9][0-9][0-9])$ to the form ^([0-9]{5,5})$ which is a bit more readable.
Your example/test should look like the following - omit the / because it is set in the RewriteBase.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^bob /about [R,NC]
</IfModule>

How to configure htaccess file for Cake 2.3.x on 1and1 shared hosting

Using the default cakephp htaccess file setup will not work on my domain when I want to install my Cakephp app in a subfolder, while everything works on localhost (xampp)
target => http://example.com/mycakeapp
Install needs 3 htaccess files:
root .htaccess
#.htaccess in root
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /mycakeapp
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
In app .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /mycakeap
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/ webroot/$1 [L]
</IfModule>
In webroot .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mycakeapp
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Following CakePHP's documentation, and Using these htaccess files, I get error500 results.
Using RewriteBase / instead of /mycakeapp will throw 404 error page.
PHP is in 5.4 version. How can I solve this?
/dirCakePhp
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /app/webroot/ [L]
RewriteRule (.*) /app/webroot/$1 [L]
</IfModule>
/direCakePhp/app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /webroot/ [L]
RewriteRule (.*) /webroot/$1 [L]
</IfModule>
/direCakePhp/app/webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
</IfModule>
Juste add '/' after RewriteRule,
And change PHP version in 1and1 hosting panel to => 5.2
Add date_default_timezone_set('Europe/Paris'); in core.php
Setup your rules like this:
.htaccess in DOCUMENT_ROOT
RewriteEngine on
RewriteBase /
RewriteRule (.*) mycakeapp/$1 [L]
.htaccess in DOCUMENT_ROOT/mycakeapp
RewriteEngine on
RewriteBase /mycakeapp/
RewriteRule (.*) app/webroot/$1 [L]
.htaccess in DOCUMENT_ROOT/mycakeapp/app
RewriteEngine on
RewriteBase /mycakeapp/app/
RewriteRule (.*) webroot/$1 [L]
.htaccess in DOCUMENT_ROOT/mycakeapp/app/webroot
RewriteEngine On
RewriteBase /mycakeapp/app/webroot/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]