I have the following url
http://mywebsite.com/browse-test.php?v=myname
I want it to be redirected to this instead
http://mywebsite.com/myname
This is what I tried so far
RewriteEngine On
RewriteCond %{HTTP_HOST} mywebsite.com/browse-test.php?v=$ [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [L,R=302]
When I looked for an answer on this website and google I didn't find any examples that made a redirect based on on a specific file and php url paramater.
This code should help.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /+browser-test\.php\?v=([^&\s]+)
RewriteRule ^ /%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /browse-test.php?v=$1 [L]
Having a look at the mod_rewrite docs to get a better understanding as MrTux noted is highly suggested to better understand the different options.
Related
I want to redirect the url of http://sitename/modules/fb/fb.php to http://sitename/modules/take_control .How can i do that using htaccess
I tried like
RewriteRule ^/?modules/fb/fb\.php$ take_control , Is that right ?
Your solution is the opposite of what you most likely want if you are trying to rewrite to take_control.
Give this a try. These rules should provide the rewrite with take_control as the URI both ways.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /+modules/fb/fb\.php [NC]
RewriteRule ^ /take_control/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^take_control/?$ /modules/fb/fb.php [L]
I have such rewrite rules
RewriteEngine On
RewriteCond %{HTTP_HOST} ^monkey.pl(.*) [NC]
RewriteRule ^(.*)$ http://www.monkey.pl/$1 [R=301,L]
RewriteRule ^horse.html$ /dog.html
and when I go to the monkey.pl/horse.html I get the message:
The requested URL /home/login/monkey/dog.html was not found on this server.
How can I get this to work. Basically what I'm trying to do is to change address of urls like:
http://www.monkey.pl/produkty.php?strona=1
to be displayed as
http://www.monkey.pl/produkty/czesci_do_mixokretow.html
but none of my rules are working. Therefore I'm trying to come with solution.
I tried many varations and I couldn't get it to work. I don't want to rewrite whole page. Just 6 pages which I need to change url and that's all. Fixed translation url => url.
If you are only doing a handful of URLs then you can do them this way.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{THE_REQUEST} /+produkty\.php\?strona=1 [NC]
RewriteRule ^ /produkty/czesci_do_mixokretow\.html [R=302,L]
RewriteRule ^produkty/czesci_do_mixokretow\.html$ /produkty.php?strona=1 [L]
RewriteRule ^horse\.html$ /dog.html [L]
I searched the forum and found some questions close to what I am trying to achieve but they don't work for what I am trying to do.
We got a new client and we need to redirect the pages of his old website to the new one.
All the pages in the old website have this structure:
http://www.domain.com/index.php?option=com_content&view=article&id=158&Itemid=179
I need to redirect each page to the relevant page of the new website. The structure of the urls in the new website is like this:
http://newdomain.website.com/slug/
I am assuming that the only way to do this is through htaccess but I cannot figure out how to write the command.
Thank u in advance for any help.
try this :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) http://newdomain.website.com/slug/$1 [L,QSA]
Put this code in your DOCUMENT_ROOT/.htaccess file on domain.com:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^option=.+ [NC]
RewriteRule ^index\.php$ http://newdomain.website.com/slug/? [L,NC,R=301]
EDIT:
RewriteCond %{QUERY_STRING} ^option=.+?&Itemid=.*?64$ [NC]
RewriteRule ^(index\.php)?$ http://newdomain.website.com/slug/? [L,NC,R=302]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{QUERY_STRING} ^option=.+?&Itemid=.*?64$ [NC]
RewriteRule ^ http://newdomain.website.com/slug/? [L,NC,R=302]
I had a previous post regarding this matter:
ISAPI_Rewrite and Coldfusion Rules
With the help of Helicon Support we were able to create the following rules:
RewriteEngine on
RewriteRule on
RewriteBase /
RewriteCond %{QUERY_STRING} ^filter=brand&brand_id=([^&]+)&brand_name=([^&]+)$ [NC]
RewriteRule ^products-search\.cfm$ /search/%1/%2.cfm? [NC,R=301,L]
RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^search/([^/]+)/([^._]+)\.cfm$ /products-search.cfm?filter=brand&brand_id=$1&brand_name=$2 [NC,L]
RewriteCond %{QUERY_STRING} ^product_id=([^&]+)&product_title=([^&]+)$
RewriteRule ^product-details\.cfm$ /%1/%2.cfm? [NC,R=301,L]
RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^._]+)\.cfm$ /product-details.cfm?product_id=$1&product_title=$2 [NC,L]
Their help was much appreciated as i am very new to URL Rewriting. The issue i am having now is that the first rule works, it turns the url from:
www.mysite.com/products-search.cfm?filter=brand&brand_id=98&brand_name=HAMANN
to
www.mysite.com/search/98/HAMANN.cfm
Since i am new to this, i do not understand how to get the css/js/images folders to display on this page, what rule or condition do i use for the RewriteBase / part so that everything on the page loads correctly?
The second part of the .htaccess rules do not actually work which change:
product-details.cfm?product_id=1&product_title=This Is A New Product
to
products/This_Is_A_New_Product.cfm
Any help would be greatly appreciated
I am working on a twitter/facebook type site for a college class. Somehow they let a professor teach this class with no PHP, CSS, HTML, JavaScript,jQuery, or Ajax knowledge. I have been trying to rewrite my URLs to make them look like twitter. I have gotten all of my user profile pages to rewrite to: www.site.com/username from: www.site.com/profile.php?name=username. However, I also want to rewrite my login page, create account page, etc. Currently they are: www.site.com/login.html , www.site.com/createAccount.html. I want the to rewrite without the html. Here is my .htaccess file currently.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?name=$1 [L]
**Update
I apologize I ended up switching all of my files over to .php. But I am still having some issues. Now, I only want to redirect specific URLs. For example: www.361orc.info/login should internally redirect to www.361.orc.info/login.php . I cannot seem to figure out what is wrong with the following code. It redirects but it does it changes the client URL. I want it to just redirect internally. Here is my .htaccess file:
RewriteEngine On
#I want this code to change .com/login.php to .com/login but only internally
#the URL in the client's browser shouldn't change
RewriteCond %{REQUEST_FILENAME} !-
RewriteRule ^login?$ login.php [L]
#Change the profile pages of users from .com/profile.php?name=user to .com/user
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/?$ /profile.php?name=$1 [L,QSA]
you could do something like this
# Rewrite User Profiles
RewriteCond %{QUERY_STRING} ^name=([^&]+) [NC]
RewriteRule ^profile.php$ /%1 [R=301,L]
# Rewrite Login
RewriteRule ^login.html$ /login [R=301,L]
# Rewrite Create Account
RewriteRule ^createAccount.html$ /createAccount [R=301,L]
You are pretty close, just an external redirection rule that will redirect .html files to ones without .html extension:
RewriteEngine On
RewriteBase /
# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+?)/?$ $1.html [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)$ profile.php?name=$1 [L,QSA]