I have this link:
index.php/forums/viewforum/5/
Now, I want that "forums" word in URL to become dynamic such that which ever word I replace it with, it still redirects to the same URL.
For example, if I have:
ProductA/viewforum/5/
it redirects to:
forums/viewforum/5/
For example, if I have:
ProductB/viewforum/13/
it redirects to:
forums/viewforum/13/
In other words, if there's a "view forum" word in the URL, it should trigger this rewrite.
I already have a .htaccess that removes the index.php from the URL so the rewrite rule should consider that too.
Is it possible?
HTACCESS:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteEngine on
RewriteCond %{REQUEST_URI} (member)
RewriteRule ^(.*)$ http://%{SERVER_NAME}/404 [R=301,L]
RewriteRule ^[.*]+/(viewforum/[0-9]+/?)$ /forums/$1 [L,NC]
RewriteCond $1 !^(images|favicon\.ico|robots\.txt|index.php) [NC]
RewriteRule ^(.*)$ /home/ddco/public_html/index.php/$1? [L]
</IfModule>
You can use this rewrite rule:
RewriteCond %{THE_REQUEST} /forums/ [NC]
RewriteRule ^ - [R=404,L]
RewriteRule ^[^/]+/(viewforum/[0-9]+/?)$ /forums/$1 [L,NC]
Also suggesting you to post your current .htaccess rules as well for further investigation.
Related
I've got two directives in my htaccess.
RewriteRule ^(it|en|de)/(.*) $2?lng=$1 [L,QSA]
That means: for all url with start with it, en, de set url variables "lng" to $lang
Now, i want that all pages that didn't start with a language code to be redirected to /it:
I try this:
RewriteCond %{REQUEST_URI} !^/(it|en|de)/{0,1}(.*)
RewriteRule ^(.*)$ /it/$1 [R=301,L]
but when i call:
http://HOST/my-page
on url, i get, with a "ERR_TOO_MANY_REDIRECTS":
http://HOST/it/my-page?lng=it&lng=it&{many-others-lng=it}
the word "/it" is added correctly at the beginning of the url, but also infinity "lng=it"
I use "L" flag: this shoud stop processing the rule set.
Any hint?
EDIT:
Add my full .htaccess
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteRule ^(it|en|de)/(.*) $2?lng=$1 [L,QSA]
RewriteRule ^catalogue-men$ views/main/pages/index.cfm?gen=1 [QSA,L]
RewriteCond %{REQUEST_URI} !^/it/
RewriteRule ^(.*)$ /it/$1 [R=301,L]
Just remember that mod_rewrite runs in loop until there is no rule that fires. You are getting redirect loop because first rule is removing /it/ from start of URI and 301 rule is adding it in front.
Reordering your rules
Using THE_REQUEST instead of REQUEST_URI
Add /catalogue-men in your skip condition
This .htaccess should work for you:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} !\s/+(?:it|catalogue-men)/ [NC]
RewriteRule ^(.*)$ /it/$1 [R=301,L,NE]
RewriteRule ^(it|en|de)/(.*) $2?lng=$1 [L,QSA]
RewriteRule ^catalogue-men$ views/main/pages/index.cfm?gen=1 [QSA,NC,L]
I am having a problem with my htaccess file, and can't figure out if it's my configuration, or something like server cache which is messing with my URLs.
My file is the following
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^website.com$
RewriteCond %{HTTPS} off
RewriteRule (.*) https://website.com/$1 [R=301,L]
RewriteRule ^([a-z]+)\/?$ $1.php [NC]
The first rule is to move www to non-www, it works.
The second rule is to move http to https, it also works.
the third rule is to make URL /anyFile call anyFile.php, but keep a lovely URL.
The problem is that it calls anyFile.html, not PHP, and if I remove said HTML file then I get 404.
Yes it works typing anyFile.php in the URL, but I would like to not have .php in the URL.
If it is not obvious enough, it is supposed to work for any file name, not just a single one.
Any and all help is much appreciated.
Replace your .htaccess rules with this code:
Options -MultiViews
RewriteEngine On
RewriteBase /
# single rule for http->https and www removal
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://website.com/$1 [R=301,L]
# hide .php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([a-z]+)/?$ $1.php [NC,L]
I'm recently learn how to do htaccess too, so I'm still a novice but I would write
RewriteRule ^([a-z]+)\/?$ helloWorld.php [NC]
to redirect it to the helloWorld.php file.
The $1 is a get parameter.
my calendar pagination like this
example.com/calendar/2014/page/2
example.com/calendar/2014/04/page/2
example.com/calendar/2014/04/05/page/2
someone go to /page/ without last number i want to redirect for without /page/ ... i want like this type.. if can someone help me for this one.
Note : i want 301 redirect
i want to redirect like this
example.com/calendar/2014/page/ (with slash or without slash) -> example.com/calendar/2014
example.com/calendar/2014/04/page/ (with slash or without slash) -> example.com/calendar/2014/04
example.com/calendar/2014/04/05/page/ (with slash or without slash) -> example.com/calendar/2014/04/05
here is my code htaccess
/calendar/.htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteBase /calendar/
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
RewriteRule ^([0-9]+)/?$ load.php?year=$1 [L,QSA]
RewriteRule ^([0-9]+)/(page)/([0-9]+)/?$ load.php?year=$1&p=$3 [L,QSA]
RewriteRule ^([0-9]+)/([0-9]+)/?$ load.php?year=$1&month=$2 [L,QSA]
RewriteRule ^([0-9]+)/([0-9]+)/(page)/([0-9]+)/?$ load.php?year=$1&month=$2&p=$4 [L,QSA]
RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/?$ load.php?year=$1&month=$2&date=$3 [L,QSA]
RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/(page)/([0-9]+)/?$ load.php?year=$1&month=$2&date=$3&p=$5 [L,QSA]
Insert this 301 rule just below your existing 1st www enforcing 301 rule:
RewriteCond %{THE_REQUEST} \s/+(.+?)/page/?[\s?] [NC]
RewriteRule ^ /%1? [R=301,L]
To note, I've found similar questions on StackOverflow but they have not worked as I need.
I have a URL such as:
http://www.example.com/index.php/test
I'd like to remove the index.php directory, so if the above is entered it would go to:
http://www.example.com/test
This appears to work
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
However if the url is:
http://www.example.com/index.php?option=example
It turns into
http://www.example.com/?option=example
So index.php should only be removed if it's a directory like in my first example.
Also if you type in for instance:
http://www.test.example.com/index.php/index.php/dfd
It should go to
http://www.test.example.com/dfd
the rules below will:
not apply for /index.php?o=a
redirect /index.php/index.php/dfd to /dfd
redirect /index.php/index.php/dfd?a=b to /dfd?a=b
redirect /index.php/index.php?a=b to /index.php?a=b
.
RewriteCond %{QUERY_STRING} .+
RewriteRule ^index\.php(/index\.php)+/?$ /index.php [R=302,L,QSA,NC]
RewriteCond %{QUERY_STRING} ^$ [OR]
RewriteCond %{REQUEST_URI} !index\.php/?$
RewriteRule ((^|/)index\.php)+/?(.*)$ /$3 [R=302,L,QSA,NC]
I have the following conditions in my .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ex\.co$
RewriteRule ^(.*)$ http://example.com/?ref=$1 [L,R]
This will forward ex.co\xxxxxx to example.com\?ref=xxxxxx.
What I want is to add a line that if a user simply goes to ex.co it redirects to example.com and not (as it does currently) example.com?ref=
Any suggestions?
Thanks!
I think you just need to add the third line below:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ex\.co$
RewriteRule ^$ http://example.com [L,R]
RewriteRule ^(.*)$ http://example.com/?ref=$1 [L,R]