I have setup .htaccess to rewrite some rules in our system and they are all working fine.
Howevever, i am having trouble with the following rule. Can anyone help with this?
I have the following URL
test.com/admin/page/files/TEMPFILES/file.pdf
I would like this to be redirected if the url contains the following two strings "/admin/page/" AND "TEMPFILES"
i would like this to redirect to the following
test.com/files/TEMPFILES/file.pdf
I have tried the following
RewriteCond %{QUERY_STRING} ^TEMPFILES
RewriteCond %{REQUEST_URI} ^admin/([a-z]+)(/.*) [NC]
RewriteRule ^(/.*)?$ $2 [NC,L,QSA]
Any help will be appreciated.
Following URL
test.com/admin/page/files/TEMPFILES/file.pdf
should redirect to
test.com/files/TEMPFILES/file.pdf
You can use this
RewriteEngine on
RewriteCond %{REQUEST_URI} /admin/page/files/TEMPFILES/(.+)\.pdf$
RewriteRule (.*) /files/TEMPFILES/%1.pdf [L,R=301]
This will redirect /admin/page/files/TEMPFILES/foobar.pdf to /files/TEMPFILES/foobar.pdf .
Related
I've two types of URLs:
http://www.example.com/?content=contact_form.php
and
http://www.example.com/?content=product.php&id=20
I changed my whole URL system like this:
http://www.example.com/file/contact_form
and
http://www.example.com/product/I-m-the-title/20
Of course I made 301 redirect with .htaccess to tell Google and co. the new URL.
I made it like this:
# Rewrite URLs
RewriteEngine On
RewriteRule ^(ignore)($|/) - [L]
RewriteRule ^file/([^/]*)$ /?content=$1.php [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /?content=$1.php&title=$2&id=$3 [L]
# Redirect old URL to new URL
RewriteCond %{QUERY_STRING} ^content=contact\_form\.php$
RewriteCond %{REQUEST_URI} ^\/$
RewriteRule .* http://www.example.com/file/contact_form? [R=301,L]
RewriteCond %{QUERY_STRING} ^content=product\.php&class=I-m-the-title$
RewriteCond %{REQUEST_URI} ^\/$
RewriteRule .* http://www.example.com/I-m-the-title/Test/20? [R=301,L]
My problem:
It's perfectly working for: http://www.example.com/?content=product.php&id=20
But for http://www.example.com/?content=contact_form.php I'm getting the message that it couldn't get opened because of too much redirect.
Does anybody know what I'm doing wrong? I hope anybody can help me soon because I have to fix it before Google misinterprets it.
Your rule cause an infinite loop because it is rewriting your uri to the same location again and again overriding your internal and external redirects.. To fix the Rewrite loop, add the following at the top of your htaccess
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
I want to create .htaccess mod rewrite but still have problem.
Suppose i created friendly URL like this :
mydomain.com/mypage/12345/title-of-news
I want that friendly URL process the below URL in hidden process :
mydomain.com/index.php?p=mypage&idnews=12345
Values of "p" and "idnews" are dynamic, so they will have different value.
I tried below code but still didn't work. Anything wrong?
RewriteBase /
RewriteCond %{QUERY_STRING} p=(\w+)&idnews=(\d+)
RewriteRule ^index.php /%1/%2 [L,R=301]
Any help would be appreciated. Sorry if this is duplicated question, if don't mind please tell me the answer link. Thanks a lot.
I think you don't need the RewriteCond you write there.
And you can use following rule
RewriteRule ^/?([0-9a-zA-Z_.-]+)/([0-9]+)/([0-9a-zA-Z_.-]+)$ index.php?p=$1&idnews=$2 [L]
If you want to change index.php?p=foo&idnews=bar to /foo/bar , try theses rules :
RewriteEngine on
##externally redirect "/index.php?p=foo&idnews=bar" to "/foo/bar"##
RewriteCond %{THE_REQUEST} /index\.php\?p=([^&]+)&idnews=([^&\s]+) [NC]
RewriteRule ^ /%1/%2? [L,R,NC]
##internally redirect "/foo/bar" to "/index.php?p=foo&idnews=bar"##
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?(.*)?$ /index.php?p=$1&idnews=$2 [NC,L]
I want to redirect this link http://www.usedcarstampa.com/blog/?m=201511
to
http://www.usedcarstampa.com/blog/
I am trying the following in .htaccess file
1) Not working
Redirect /usedcarstampa.com/blog/index.php?m=201511 /index.php
2) Not working
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)m=201511(&|$) [NC]
Rewrite-rule ^index.php$ /? [R=301,NC] // not working
note :- main site in core PHP and blog part in word-press
there is also a another ht-access file in blog/ directory. I am also try above code to right there but i not get positive result
please help,thanks in advance
Try this rule as very first rule in your /blog/.htaccess:
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)m=201511(&|$) [NC]
RewriteRule ^(index\.php)?$ /? [R=301,L]
i have a trivial question about htaccess rewrite condition.
The think i want to do in my htaccess is:
When someone accesses my project from a url different from "example.com" to be redirected to a specific controller, for example app_user.php
I need the syntacs for this condition redirect.
Thanks for your time
Try this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/app_user.php
RewriteRule ^ /app_user.php [L]
been stuck at this for the past couple of hours here. Let me just illustrate my problem simply by the following lines.
Here's
1) Joomla absolute URL for the page i'm trying to convert: http://classifiedads4free.com/index.php?option=com_adsmanager&view=front
then:
Created menu item and activated SEF urls: So now alias becomes http://classifiedads4free.com/ads
after which:
I added a query string at the back of the URL so it becomes: http://classifiedads4free.com/ads?country=Singapore.
Was just wondering if there's anyway i can make the url at the top http://classifiedads4free.com/ads?country=Singapore. -->http://singapore.classifiedads4free.com
Tried going back to using the absolute URL on my .htaccess file, Following is the code:
1st tried:
RewriteCond %{HTTP_HOST} ^(.+)\.classifiedads4free\.com$
RewriteCond %{HTTP_HOST} !^www\.classifiedads4free\.com$
RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|bmp)$ [NC]
RewriteRule (.*) ads?country=%1 [L]
2nd tried:
RewriteCond %{HTTP_HOST} ^(.+)\.classifiedads4free\.com$
RewriteCond %{HTTP_HOST} !^www\.classifiedads4free\.com$
RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|bmp)$ [NC]
RewriteRule (.*) index.php?option=com_adsmanager&view=front&country=%1 [L]
However, I can't seem to get the redirect working. It keeps redirecting me back to my home page which isn't what i requested.
Would appreciate if someone could provide some assistance here. Been trying all day long.
Try this:
RewriteRule ^(.*)$ http://www.classifiedads4free.com/ads?country=%1 [L,NC]