I am building a php framework and at the moment i have these .htaccess rules for directing to my index and getting the controllers and arguments from the URL
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php/$1
But since the site is not ready yet I need to add a rule for when accessing root directly to forward to comingsoon.php
any idea how?
Add this rule before the other one. This matches www.site.com or www.site.com/
RewriteRule ^/?$ /commingsoon.php
Pasted from Symfony2 Framework .htaccess file (replaced app.php with index.php) but it should works. Try it:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
Related
I would like to modify my htaccess to :
Redirect all *.php calls to app.php (SEO call to keep ranking from migration)
Avoid redirection loop excluding app.php for rewrite rule above.
I ended up with this :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !app\.php$
RewriteRule ^(.*)\.php?$ /app.php/ [R=301,L]
[...]
</IfModule>
But this produces a 404 on test url like http://example.com/sqdlkqjsdlsqk.php
What's wrong in here?
Regards,
You should be using this rule without trailing slash after app.php:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/app\.php$ [NC]
RewriteRule ^(.+)\.php$ /app.php [R=301,L,NC,NE]
Make sure to clear browser cache before testing this change.
Check this out. Make sure to clear your cache.
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
I have a PHP MVC frame work.
I created a subdomain but it gives the error 500.
My root .htaccess file is like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ all_users/ [L]
RewriteRule (.*) all_users/$1 [L]
It redirects to the "all_users" folder.
The "all_users" root .htaccess is like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
The subdomain folder is in root of site.
How should I change the .htaccess file(s) for subdomain
redirection. Thanks.
I found the answer.
This is the .htaccess file in root of site:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$ [NC]
RewriteRule (.*) / [L]
RewriteRule ^$ all_users/ [L]
RewriteRule (.*) all_users/$1 [L]
</IfModule>
I need to remove locale from url in htaccess symfony2
for example:
site.de/de/....
to
site.de/....
symfony default htaccess looks like this:
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
how can i remove locale in a safe way without breaking any routing.
I have a small question.
I have build a system and it is using a .htaccess to direct the traffic to the correct locations.
Now I have the following .htaccess data
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
RewriteRule (.*) core/$1 [L]
///### (does not work.. this is a problem) RewriteRule (.*) app/template/ !page [L]
</IfModule>
The problem is actually that when I want to show a .css file located in /app/templates it also redirects to /core/
I tried to make an exception. However that does not really seem to work at my method.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
RewriteRule (.*) core/$1 [L]
RewriteRule (.*) app/template/ !page [L]
</IfModule>
This .htaccess gives a 500 error.
Could anyone tell me what I am doing wrong? And how I can make the exception work for the template directory?
TIAD!!
You should use:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) core/$1 [L]
</IfModule>
I am running into an infinite redirection loop when setting up CakePHP on a bluehost server.
I have set my .htaccess as follows,
Under /home/mysite/public_html/site2 (I have configured an add-on domain with site2 as its serving directory on BlueHost)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Under /home/mysite/public_html/site2/app as,
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
And finally under /home/mysite/public_html/site2/app/webroot as,
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
If I remove the two RewriteCond from the .htaccess under webroot the Cake controllers start working but I don't see any images or CSS. I am not sure where am I going wrong.
creat a htaccess in root same as
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site2\.tld[NC]
RewriteRule ^$ site2/app/webroot/ [L]
RewriteCond %{HTTP_HOST} ^site2\.tld[NC]
RewriteRule (.*) site2/app/webroot/$1 [L]
</IfModule>`
and htacess in site2 folder must be
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]