Usually is the other way aroud, but I need to redirect my static urls to dynamic ones as a variable part of the first one.
I need to redirect:
http:/example.com/sub1/sub-2/2014147-test-page-45x.html
http:/example.com/sub1/sub-6/8014149-test-24page.html
http:/example.com/sub1/sub-25/7514157-58test-page.html
to
http://example.com/sub1/testing.php?s=2014147
http://example.com/sub1/testing.php?s=8014149
http://example.com/sub1/testing.php?s=7514157
I know I need to use %{REQUEST_URI}, but I can't put it together.
Any help will be appreciated.
Thanks.
Assuming your .htaccess is at root of example.com, adding following to it will do the trick.
RewriteEngine On
RewriteBase /
RewriteRule ^sub1/[^/]+/(\d+).*$ sub1/testing.php?s=$1 [R,L]
This should work:
RewriteEngine on
RewriteRule ^sub1/(.*)/([0-9]+)-(.*)$ /sub1/testing.php?s=$2 [R=301,L]
Related
I need to redirect a dynamic url to another url, with the dynamic portion intact, for example:
http://www.mydomain.com/VARHome.aspx?var=32
needs to redirect to:
To: http://www.otherdomain.com/VARHome.aspx?var=32
The value after "var=" is dynamic, it can be any number.
This needs to be done via .htaccess.
Thanks for any help!
I'm thinking RewriteRule ^(.*)$ http://www.otherdomain.com/$1 [R=301,L] or something along those lines should do the job.
Edit: Maybe something like
RewriteRule ^VARHome.aspx?var=(.*)?$ http://www.otherdomain.org/VARHome.aspx?var=$1/ [R=301,L]
if you are in mydomain.com, write in .htaccess
RewriteEngine on
RedirectMatch 301 ^/VARHome.aspx?var=(.*)$ http://www.otherdomain.com/VARHome.aspx?var=$1
I have a website set up where I store all my user profiles in /member-centre/member-directory/USERNAME
My problem is that a number of referrals are posting to a depreciated structure of /members/USERNAME
Is there a way I can configure my .htaccess file to automatically post the requested USERNAME to the correct location? All i've found on google is static redirection.
If this is not possible through .htaccess, is there another method I could use?
Many thanks in advance
If you are looking for a redirect solution, Jon Lin's will work fine. If you want to do a rewrite then put the following in your .htaccess file in the root of your domain
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/members/([^/]+)$ [NC]
RewriteRule . member-centre/member-directory/%1 [L]
if member/centre etc is relative to the root filesystem and not your domain then replace the last line with (just leading slash)
RewriteRule . /member-centre/member-directory/%1 [L]
Do you mean something like:
RedirectMatch 301 ^/members/([^/]+)/? /member-centre/member-directory/$1
This redirects the browser with a permanent redirect.
Try something like this:
RewriteRule ^members/ /member-centre/member-directory/ [L]
I need a redirect from http://www.mysite.com/passport/365.html to http://www.mysite.com/passport/365.html?task=view
I try to do it like this
RewriteCond %{HTTP_HOST} ^/passport/365.html$
RewriteRule ^/?$ /passport/365.html?task=view [QSA]
and it doesn't work.
Please help.
try that :
RewriteEngine on
RewriteRule ^passport/365\.html$ http://www.mysite.com/passport/365.html?task=view [R]
I think in you example ur missing the **
so it should be something like :
RewriteRule ^/passport/365\.html$ /passport/365\.html?task=view [QSA]
I would recommend you use this plugin.
You can simply add the redirect rule to the plugin without modifying .htaccess
There is a component already build in Joomla called "redirect" where U can set-up your redirects, so you don't have to use .htaccess at all.
Here is a good tutorial: http://www.joomtraining.com.au/tutorials/joomla-1.6/creating-a-page-redirect
The problem with the .htaccess is that every redirect must be set in appropriate place in the file.
I am simply trying to get this URL:
http://foo.com/entry/random-entry-123
to redirect to:
http://foo.com/random-entry-123
The "random-entry-123" is dynamic. Different for each entry.
Any help with this is greatly appreciated!
Assuming no further rewrites are in use, and all links inside /entry/ are to rewritten, then try this:
RewriteEngine on
RewriteBase /
RewriteRule ^/entry/(.+)$ /$1 [L,QSA]
Lose the [L] if there are further rewrites ahead in the file.
Although this has already been answered, it didn't work for me when I had two segments after the first, eg:
http://foo.com/entry/random-segment/random-entry-123
Instead this worked for me and also takes care of 301 redirects:
RedirectMatch 301 /entry/(.*) /$1
Hope this helps.
I have a url like this.
/domains/details.php (NOTE: domains is dynamic and can be anything)
How do I remove the domains part from the URL using .htaccess so the actual lookup is:
/details.php
OR it'll be cool if I can get domains into the URL.
/details.php?page=domains
Thanks!
Scott
RewriteEngine on
RewriteBase /
RewriteRule ^([^/]+)/details.php$ /details.php?page=$1 [R=301]
Leave off the [R=301] if you want an internal redirect rather than an actual HTTP redirect.
To preserve existing query parameters you can change the rule to this:
RewriteRule ^([^/]+)/details.php(.*)$ /details.php?page=$1&%{QUERY_STRING} [R=301]
Please try to use the following rules to deal with your last request:
RewriteRule ^(?!domains/.*)([^/]+)/details.php$ domains/details.php?page=$1 [R=301,QSA]
RewriteRule ^domains/details.php$ details.php [NC,L]