The problem is that when I want to access my website like www.example.com/my/subpage all works great but when I try to access my website like this (without WWW) example.com/my/subpage TYPO3 breaks it down and redirect it to www.example.com/index.php/subpage.
The redirect from non WWW to WWW is correct but why does it destroy my url? Here is the .htaccess redirect:
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
For the "nice" urls I use the realURL extension. Any ideas?
Edit (more htaccess):
RewriteRule ^(typo3|t3lib|tslib|fileadmin|typo3conf|typo3temp|uploads|showpic\.php|favicon\.ico)/ - [L]
RewriteRule ^typo3$ - [L]
RewriteRule ^typo3/.*$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php
Keep your 301 rules before other internal rewrite rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^ http://www.example.com%{REQUEST_URI} [L,R=301,NE]
RewriteRule ^(typo3|t3lib|tslib|fileadmin|typo3conf|typo3temp|uploads|showpic\.php|favicon\.ico)/ - [L]
RewriteRule ^typo3(/.*)?$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php [L]
Also test this in a new browser to avoid browser caching issues.
Related
I have the following code in my htaccess file which is supposed to redirect all www requests to the non www version of index.html, but its not working and I'm not sure why. Can anyone help?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Have it like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^index\.html$ - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
Here we are capturing value after www. in a capture group and then using that as %1 in target URL.
Make sure to clear your browser cache or use a new browser before you test this change.
Cannot use (!) reverse operation, a redirect URL (http://ssvwv.com) will appear:
/1/3/ktrb
Will not display (index.html)
RewriteEngine on
RewriteCond %{REQUEST_URI} !^\/1\/(?:1|2|3)\/.*$
RewriteRule ^(.*)$ http://ssvwv.com/ [L,R=302,NE]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . /index.html [L]
This should work for you:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(?:index\.html|1/[1-3]/.*)$ [NC]
RewriteRule ^ http://ssvwv.com/ [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.html [L]
Issue is that last rule is rewriting to /index.html and when mod_rewrite loops again URI becomes /index.html and RewriteCond %{REQUEST_URI} !^\/1\/(?:1|2|3)\/.*$ returns true thus redirecting to http://ssvwv.com/. That's why you need to skip /index.html from first rule as well.
I'm trying to exclude a directory that's 1 level deeper than one that already has a redirect.
So Redirect /department/team/
but exclude /department/team/employee/
I've already tried
RewriteCond %{REQUEST_URI} !^/department/team/employee/
and
RewriteRule ^/department/team/employee/ - [L]
Here's current htaccess.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/$ $1 [R=301]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
##RewriteCond %{REQUEST_URI} !^/department/team/employee/
RewriteRule ^/department/team/employee/ - [L]
Redirect 302 /department/team/ https://example.com
Sorry for not-very-clear title.
I'm using FatFreeFramework with his .htaccess:
RewriteCond %{REQUEST_URI} \.ini$
RewriteRule \.ini$ - [R=404]
#RewriteCond %{REQUEST_URI} \.html?$
#RewriteRule \.html?$ - [R=404]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Now, restyling an old site, I have in Google some url codified like
www.example.com/index.php?ID=12
I would strip away that and redirect them to home page.
I don't know how write the rule, I did try to edit in this mode but without luck:
RewriteCond %{REQUEST_FILENAME} !-d
Redirect 301 /index.php?ID=$1 index.php
RewriteRule .* index.php [L,QSA,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Right above this rules:
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Add this:
RewriteCond %{THE_REQUEST} \ /+index\.php\?ID=[0-9]
RewriteRule ^ / [L,R=301]
You can't match against the query string using mod_alias's Redirect directive.
What I have in my htaccess file:
RewriteEngine on
# --- Remove index.php from URLs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule .* index.php/$0 [PT,L]
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^city/([^/]+)/?$ /uk/city/$1 [R=301,L]
What I like it to do is redirect example.com/city/london to example.com/uk/city/london
The weird thing is that it now redirects to example.com/uk/city/london?city/london so it seems it adds the part it needs to redirect as a get parameter to the new URL.
Also tried Redirect 301 /city/london http://www.example.com/uk/city/london but this gives the same result.
You need to keep R=301 (redirect) rule before internal routing rule:
RewriteEngine on
RewriteRule ^city/([^/]+)/?$ /uk/city/$1 [R=301,L]
# --- Remove index.php from URLs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule .* index.php/$0 [PT,L]
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Also clear your browser cache to test this to avoid hitting old 301 cache.
You can try something like this if the Redirect 301 did not work:
RewriteRule /city/london uk/city/london [L]
Here's an example with your other defined .htaccess rules:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule /city/london uk/city/london [L]
# --- Remove index.php from URLs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule .* index.php/$0 [PT,L]
RewriteRule ^(.*)$ index.php?/$1 [L]