This should be easy, but it really isn't.
I want to accomplish this:
http://finaldomain.com/PAGENAME is the url I would like
to use.
http://subdomain.generaldomain.com/index.php?/static-parameter/PAGENAME is what the server needs to render the page
A mirroring with htaccess is what I am looking for. Not a redirect.
Can this be done?
Thanks in advance,
Diederik
Try this .htaccess in your document root.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?finaldomain\.com$ [NC]
RewriteRule ^(.*)$ http://subdomain.generaldomain.com/index.php?/static-parameter/$1 [L]
This would redirect
http://www.finaldomain.com/file.php => to =>
http://subdomain.generaldomain.com/index.php?/static-parameter/file.php
http://finaldomain.com/subfolder/file.php => to =>
http://subdomain.generaldomain.com/index.php?/static-parameter/subfolder/file.php
Related
Part of my .htaccess code is as follows:
RewriteRule ^([A-Z]+)*$ nextlevels_state.php?state=$1 [L]
RewriteRule ^([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC]
This basically redirects URL, example.com/XX to example.com/nextlevels_state.php?state=XX and example.com/XX/1 to example.com/nextlevels_state.php?state=XX&page=1 (internally).
Now, I would like to change the URL structure of the URL from example.com/XX to example.com/nextlevels/XX and example.com/XX/1 to example.com/nextlevels/XX/1
and I tried changing .htaccess to as follows:
RewriteRule ^nextlevels/([A-Z]+)*$ nextlevels_state.php?state=$1 [L]
RewriteRule ^nextlevels/([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC]
However, as the site urls are already indexed in search engines, I would like to know a way to redirect all the traffic from example.com/XX to example.com/nextlevels/XX (externally) using .htaccess .
Please guide me in this regard. Thank you community :)
Could you please try following, written and tested with shown samples only(improving your already done attempts here). Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Rule for redirect to url example.com/nextlevels/XX.
RewriteRule ^([A-Z]+)$ nextlevels/$1 [R=301]
RewriteRule ^nextlevels/([A-Z]+)/?$ nextlevels_state.php?state=$1 [NC,L]
##Rule for redirect to url example.com/nextlevels/XX/1.
RewriteRule ^([A-Z]+)*/([0-9]+)$ nextlevels/$1/$2 [R=301]
RewriteRule ^nextlevels/([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC,L]
I want to redirect the /page/2 style pagination pages to ?page=2 and to the others in this format.
So any urls like these:
https://www.example.com/dogs/page/2
https://www.example.com/horses/videos/page/3
https://www.example.com/cats/photos/page/4
will be redirected to:
https://www.example.com/dogs?page=2
https://www.example.com/horses/videos?page=3
https://www.example.com/cats/photos?page=4
Could you please try following, written based on your shown samples. Please make sure you clear your browser cache before testing these URLs.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/(.*?)/([^/]*)/([^/]*)/?$
RewriteRule ^(.*)$ %1?%2=%3 [L]
You may use this rule:
RewriteEngine On
RewriteRule ^(.+)/page/(\d+)/?$ $1?page=$2 [L,NC,QSA]
I need to rewrite only 1 specific URL
from
http://www.domainname.com/index.php?route=payment/axis/callback
to
http://www.domainname.com/payment/axis/callback
I tried these two from stack overflow, I don't know why its not working
1st one :
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?route=payment/axis/callback [NC,L]
2nd one :
RewriteRule ^index.php?route=payment/axis/callback payment/axis/callback [L]
Try this:
4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
See the full page here.
Hope it helps!
I wouldn't use .htaccess with RewriteRule, since there are often problems with it. A simple workaround (with PHP redirect):
<?php
if($_GET['route'] == 'payment/axis/callback') {
header("Location: http://www.domainname.com/payment/axis/callback");
}
?>
You can either use h0ch5tr4355's workaround or you can try this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^route=payment/axis/callback$
RewriteCond %{SCRIPT_FILENAME} index.php
RewriteRule (.*) /payment/axis/callback [NC,QSD]
If you instead of a rewrite would like it to redirect to the new url you can add R=301 to the flags of the RewriteRule.
I have new Content Management System which rewrite old static code.
I want to redirect some old page to some new page, for example I want to redirect 3 pages only to 3 new pages:
domain.com/oldpage1 => domain.com/new/newpage1
domain.com/oldpage2 => domain.com/new/newpage2
domain.com/oldpage3 => domain.com/new/newpage3
how to do it with .htaccess?
You can use mod_rewrite for stuff like that. Have a look here:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
There are many possibilities and the exact commands depend on your link structure, but in principle (assuming that its about redirecting domain.com/mypageto domain.com/new/mypage) it works like that in your .htaccess:
RewriteEngine On
RewriteRule ^$ /new [L]
Edit: Of course you will have to install / activate Apaches mod_rewrite beforehand if its not already enabled.
This should be fairly simple. Use these 3 rules in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^oldpage1/?$ /new/newpage1 [L,NC,R=301]
RewriteRule ^oldpage2/?$ /new/newpage2 [L,NC,R=301]
RewriteRule ^oldpage3/?$ /new/newpage3 [L,NC,R=301]
I know there are plenty of questions like I asked, but searching all day the soluation, I didnt find right one that would work for me, therefore I asked question.
Here is .htaccess code I have to view user profiles:
RewriteRule ^users/([^/\.]+)/$ viewProfile.php?user=$1&%{QUERY_STRING}
RewriteRule ^users/([^/\.]+)/([^/\.]+)/$ viewProfile.php?user=$1&usr_profile=$2&%{QUERY_STRING}
And using this rewrite users profile URL is:
http://www.domain.com/users/username.html
Inside of this type of URL, I would like to create subdomain users URL, like:
http://username.domain.com
Can anyone suggest the solution?
Thanks a lot.
Make sure your vhost is setup to accept requests for *.domain.com. Then add this above your other rewrite rules:
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^$ viewProfile.php?user=%1 [L,QSA]