This is my code:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !kaomadmin
RewriteCond %{REQUEST_URI} !article
RewriteCond %{REQUEST_URI} !commentaire
RewriteRule ^([a-zA-Z0-9\-]+)/?$ page/page_url?url=$1 [L,QSA]
RewriteCond %{REQUEST_URI} !kaomadmin
RewriteCond %{REQUEST_URI} !commentaire
RewriteCond %{REQUEST_URI} !article/ajout
RewriteCond %{REQUEST_URI} !article/index
RewriteCond %{REQUEST_URI} !article/modification
RewriteRule ^article/([a-zA-Z0-9\-]+)/?$ article/article_url?url=$1 [L,QSA]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . index.php [L]
It works on localhost, but not on any of my online websites... I saw that httpd.conf AllowOverride must be set to all but i don't have that permission... and i don't see mod_rewrite on my php_info... maybe i missed something?
I tried with some htaccess tester and it works too ! I think my only problems are servers restriction... any idea?
Thanks in advance
Related
I have recently detected through https://httpstatus.io/ that our .htaccess file while working is causing a double redirect where a single redirect should only be necessary. We are redirecting pages from our old website http://www.gaconsulting.co.kr to our new website which is in a subdirectory at http://www.gaconsulting.co.kr/au/
I would greatly appreciate any advice anyone can provide into how to modify the existing .htaccess to minimize it to a single redirect.
The .htaccess contents are below:
<IfModule mod_substitute.c>
SubstituteMaxLineLength 10M
</IfModule>
# BEGIN WordPress
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/admin/?$
RewriteCond %{REQUEST_URI} !^/css/?$
RewriteCond %{REQUEST_URI} !^/cssmenu/?$
RewriteCond %{REQUEST_URI} !^/easybox/?$
RewriteCond %{REQUEST_URI} !^/etc/?$
RewriteCond %{REQUEST_URI} !^/fck/?$
RewriteCond %{REQUEST_URI} !^/greybox/?$
RewriteCond %{REQUEST_URI} !^/images/?$
RewriteCond %{REQUEST_URI} !^/inc/?$
RewriteCond %{REQUEST_URI} !^/includes/?$
RewriteCond %{REQUEST_URI} !^/jmenucss/?$
RewriteCond %{REQUEST_URI} !^/js/?$
RewriteCond %{REQUEST_URI} !^/lib/?$
RewriteCond %{REQUEST_URI} !^/mail/?$
RewriteCond %{REQUEST_URI} !^/member/?$
RewriteCond %{REQUEST_URI} !^/menujs/?$
RewriteCond %{REQUEST_URI} !^/myform/?$
RewriteCond %{REQUEST_URI} !^/popeye_css/?$
RewriteCond %{REQUEST_URI} !^/popeye_lib/?$
RewriteCond %{REQUEST_URI} !^/Scripts/?$
RewriteCond %{REQUEST_URI} !^/style/?$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) http://www.gaconsulting.co.kr/au/ [R=301,L]
# Disable the server signature
ServerSignature Off
That rule will never redirect, since all RewriteConds need to match. Something else on your server is causing the double redirect.
I am trying to create .htaccess to create friendly url.
I have made some of the urls work but the others not working. I am using the following code in .htaccess file.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.airporttransfer4u.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.airporttransfer4u.co.uk/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^195\.20\.236\.228
RewriteRule (.*) http://www.airporttransfer4u.co.uk/$1 [R=301,L]
ErrorDocument 404 /404.php
RewriteBase /
RewriteCond %{REQUEST_URI} !^/admin/
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|css|js|etc|flv|swf|mp4|mov)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
RewriteRule ^recover/([^/]*)$ /recover.php?mode=$1 [L,QSA]
The url for recover.php is failing but index.php rule is working. Recover.php rule directing to 404 page.
I also have multple variable urls to convert to friendly url. Example
index.php?p=blog_item&id=52
Any idea why it is failing?
Have your rules in this order:
ErrorDocument 404 /404.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.airporttransfer4u\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.airporttransfer4u.co.uk/$1 [L,R=301]
RewriteRule ^recover/([^/]+)/?$ /recover.php?mode=$1 [L,QSA]
RewriteCond %{REQUEST_URI} !^/admin/
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|css|js|etc|flv|swf|mp4|mov)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?p=$1 [L,QSA]
need some solution here with redirecting all of my domain (a.e mysite.co.uk, mysite.org etc)
to the .com version.
My .htaccess contains the following code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} https [OR]
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [QSA,L,NC]
</IfModule>
Please help me out here
Thanks in advance
Nevermind, I think I have just found the solution:
I have added the following lines to my .htaccess
RewriteCond %{HTTP_HOST} !^(www\.)mysite\.net$ [NC]
RewriteRule ^(.*)$ http://www.mysite.net/$1 [L,R=301]
I hope this is correct way of doing this?
I know there are some questions like this out there but the solutions are not helpful for me.
I´m using htaccess to redirect to the index.php if the request file isn´t defined (code above).
I´d like to add a code-line that if the user requests for example:
http://www.example.com/test/index.php
he will redirect to
http://www.example.com/test/
but internal it will redirect to the index.php.
Is there a way to extend my code so that it works like I want it to?
# Add Slash
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
# Redirect to index.php if the following sites were not match
RewriteBase /
RewriteCond %{REQUEST_URI} \.(php|sql|tgz|gz|txt|ttf|TTF|log|txt|ini|html|xml|xhtml|htm)$
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_URI} !^/phpinfo.php$
RewriteCond %{REQUEST_URI} !^/out.php$
RewriteCond %{REQUEST_URI} !^/sitemap[^0-9]*\.xml$
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
Complete code:
DirectoryIndex index.php index.html
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# Take off index.php
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} \.(php|sql|tgz|gz|txt|ttf|TTF|log|txt|ini|html|xml|xhtml|htm)$
RewriteCond %{REQUEST_URI} !^/((index|phpinfo|out)\.php|robots\.txt|sitemap[^0-9]*\.xml)$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?dir=$1 [QSA,L]
# Add Slash for non-files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
I am trying to add a "/login" to wildcard subdomains.
For example:
*.example.com would be redirected to *.example.com/login
but, i want certain subdomains not to be redirected, such as...
help.example.com, m.example.com, etc.
What is the best way to do this, and would this be done in .htaccess or in httpd.conf?
Thank you for your help.
Updated below:
Here is what I currently have:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^m.example.com$
RewriteCond %{HTTP_HOST} ^(.+).example.com$ [NC]
RewriteRule ^/$ https://%1/login [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You were almost there
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^m\.example\.com$
RewriteCond %{HTTP_HOST} !^help\.example\.com$
RewriteCond %{HTTP_HOST} ^(.+\.example\.com)$ [NC]
RewriteRule ^/?$ https://%1/login [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>