I've seen plenty of answers here about this question but none seem to help me.
I have a list of about 300 URLs that all have parameters in them. I want to redirect each one to different URLs on a new domain. The thing is, the redirection is determined by the content of the page, not param name = page name or something of the sort.
So, I have a list of old page = new page, how would I create something like that in htaccess?
If there were no parameters I would do:
Redirect 301 /old-page-name/ http://newurl.com/new-page-name
however that doesn't work.
Any ideas?
Edit:
I tried this and it doesn't work. Possibly this would be easier for anyone to help out with?
RewriteCond %{HTTP_HOST} muflaim\.co\.il [NC]
RewriteCond %{REQUEST_URI} ^/shop/classic?page=shop.product_details&category_id=&flypage=flypage_experience.tpl&product_id=200$
RewriteRule ^(.*)$ http://www.dreambox.co.il/45217/ [R=301,L,NC]
Just in case anyone finds this helpful, this did the trick:
RewriteEngine on
RewriteCond %{HTTP_HOST} muflaim\.co\.il [NC]
RewriteCond %{QUERY_STRING} ^page=shop.product_details&category_id=&flypage=flypage_experience.tpl&product_id=200$ [NC]
Rewriterule ^shop/classic$ http://www.dreambox.co.il/45217? [R=301,L,NC]
Related
At this moment I have a situation in which pretty url's are rewritten so that everything goes by the index.php, while maintaining the $_GET variables. The htaccess looks as follows:
RewriteEngine On
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?p=$1&projectid=$2&sub=$3&type=$4
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?p=$1&projectid=$2&sub=$3
RewriteRule ^([^/\.]+)/([^/\.]+)?$ index.php?p=$1&projectid=$2
RewriteRule ^([^/\.]+)/?$ index.php?p=$1
This works fine. However, I want it to work the other way around as well. If someone goes to http://www.example.com/index.php?p=page&projectid=123 that they will be redirected to http://www.example.com/page/123.
Is this possible, and if so, how? All I've managed so far is creating a redirect loop.
For those interested, the redirect loop I created looks as follows:
RewriteCond %{QUERY_STRING} ^p=([^&]+)
RewriteRule ^/?index\.php$ http://www.example.com/%1? [L,R=301]
I want it to work the other way around as well. If someone goes to http://www.example.com/index.php?p=page&projectid=123 that they will be redirected to http://www.example.com/page/123
Yes it indeed possible but you will need to use THE_REQUEST variable for that.
RewriteCond %{THE_REQUEST} \s/+index\.php\?p=([^\s&]+)&projectid=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]
You can build similar rule for other URLs as well.
I recently developed a web site using php which accepts a id as its input via get.
http://website.com/profile.php?id=123. its the old fashion way, I've seen sites use pretty url's like http://website.com/username.html
So in order to archive this, i managed to do some research and end up with this code blow.
Also i'm passing the username in the query string.
http://website.com/profile.php?id=123&username=test_user
the parameter ID is only used as a input for the profile.php
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /profile.php [NC]
RewriteCond %{QUERY_STRING} ^id=([^&]+)&username=([^&]+) [NC]
RewriteRule ^.* http://%{HTTP_HOST}/%2.html [R=301,L]
The final output i seek is http://website.com/username.html
Is their anything wrong in this ? this doesn't seem to work. Am i doing something wrong ? if so please be kind to let me know where my error lies. Thank you.
Try this rule:
RewriteEngine On
RewriteRule ^profile/([^/\.]+)/([^/\.]+).html/?$ profile.php?id=$1&username=$2 [L]
then you should be able to use
http://website.com/profile/123/username.html
as the URL. You can ignore the profile part but I don't recomment it because it would clash with other URLs of your website.
If you only need the username, use
RewriteRule ^profile/([^/\.]+).html/?$ profile.php?username=$2 [L]
and the URL would be
http://website.com/profile/username.html
You can use this rule:
RewriteEngine On
RewriteCond %{THE_REQUEST} /profile.php\?id=([^&]+)&username=([^&]+) [NC]
RewriteRule ^ /%1/%2.html? [R=301,L]
RewriteRule ^([0-9]+)/([^/.]+)\.html$ profile.php?id=$1&username=$2 [L,QSA,NC]
I need to convert "subdomains" to variables using htaccess.
But I don't want the original url to be displayd after the rewrite.
Here's what I have so far:
rewritecond %{http_host} ^([A-Za-z0-9-]+)\.mysite.\com$ [nc]
rewriterule ^(.*)$ http://www.mysite.com/$1?aff=%1 [nc]
But it doesn't seem to work.
What I need is the following:
User links to:
aff1.mysite.com
The displayed url changes to:
www.mysite.com/
But the actual url that the server reads is:
www.mysite.com/?aff=aff1
I'm also going to be adding languages to the mix, so I might even need something like the following:
User links to: aff1.mysite.com
Then I get the language from a cookie {HTTP_COOKIE} lang=([A-Za-z]+)$
If there's nothing in the cookie, the default should be "en"
Then the user gets redirected to aff1.en.mysite.com
Which should then be displayed as: www.mysite.com/en/
but to the server: www.mysite.com/?lang=en&aff=aff1
Please tell me this is possible, and how I can achieve this. I'm very new to rewriting. And I've viewed other questions and tried their solutions, but somehow can't adapt it to exactly what I need.
Also... www.mysite.com shouldn't go to www.mysite.com/aff=www
It should just go to /mysite.com/en/
So, I've spent way more time than I wanted to on this, but finally got something working. Instead of passing the variables in the url, I'm dropping a cookie (which was ultimately what I was doing on the page anyway, but this cuts out a step - and I didn't know that you could drop cookies with the rewrite).
If anyone has a better solution with less lines of code, please feel free to comment or post a new answer.
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{http_host} ^www.example.info [nc] #if url starts with www.example.info
RewriteRule ^(.*)$ http://example.info/$1 [r,nc] #rewrite without the www
RewriteCond %{http_host} ^www.(.*).example.info [nc] #if url starts with www.(aff).example.info
RewriteRule ^(.*)$ http://%1.example.info/$1 [r,nc] #rewrite without the www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{http_host} ^(.*)\.example.info [nc] #if subdomain is aff
RewriteRule ^(.*)$ - [co=aff:%1:example.info:7200:/] #drop/update cookie with aff
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{http_host} ^(.*)\.example.info [nc] #if subdomain is aff
RewriteRule ^(.*)$ http://example.info/$1 [nc,R,L] #rewrite without subdomain
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]
Well I'm making profile pages so right now it looks like this
http://example.com/random/?user=Robert
What I want to do is remove ?user= from the URL so the page appears as
http://example.com/random/Robert
Iv'e searched and I can't find anything working for me.
Thanks!
Based on http://statichtml.com/2010/mod-rewrite-baseon-on-query-string.html this should do the trick:
RewriteCond %{QUERY_STRING} ^user=(.*)$ [NC]
RewriteRule ^random$ random/$1 [NC,L,R=301]
The first step is to make all of your links in this form http://example.com/random/Robert, then in the htaccess file in your document root, add:
RewriteEngine On
RewriteRule ^random/(.+)$ /random/?user=$1 [L]
But to handle 301 redirects to your old URLs, you can include this:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /random/\?user=([^\ ]+)
RewriteRule ^random/$ /random/%1 [R=301,L]