I have a site which has a url structure like so:
url/example1/sometext
So I dont have to go through and change a crazy amount of code, can I use htaccess to do the following?
url/newword/sometext redirects to: url/example1/sometext with url/newword/sometext still shown the address bar.
I have tried some rewrites like:
RewriteRule ^(.*)example1(.*)$ url/$1newword$2 [R=301,L]
Any ideas?
As long as the "url" part is still the same, then you can just get rid of the R=301 flag:
RewriteRule ^(.*)example1(.*)$ /$1newword$2 [L]
Related
I would like to redirect all my urls replacing %23 with a # in my htaccess file
Example: http://afdelingtest.nl/vierdaagsefeesten/programma/%23jaap-categorie should be http://afdelingtest.nl/vierdaagsefeesten/programma/#jaap-categorie
The last part 'jaap-categorie' differs.
I tried many example Htaccess lines but nothing seems to work. Like: RewriteRule ^(.#.) /$1 [R,NE]
Can somebody help me achieve this?
Best, Jaap
This expression might help you to write a RewriteRule and do so:
^(.*)(%23)(.*)$
The hex code for hashtag is \x23. You want to replace it with $1\x23$3.
This graph shows how that expression would work:
Your RewriteRule might look like something similar to:
RewriteRule ^(.*)(%23)(.*)$ $1\x23$3 [NE,R=301,L]
or
RewriteRule ^(.*)(%23)(.*)$ $1\x23$3 [NE,R=302,L]
302 is temporary and 301 is permanent, however you wish. You might want to do a 302, then change it to 301.
You might want to clear your browser cache every time you change your .htaccess file.
I'm assuming that you have one %23 in your URLs.
Have been trying to change my urls to make them more SEO friendly
and at the moment have managed to get them sort of working how
I want it.
My original url is this:
http://www.example.com/index.php?keyword=nikon
So managed to get this rewriting so that it now looks like this:
http://www.example.com/compare/nikon.html
Using this:
RewriteEngine On
RewriteRule ^compare/([^/]*)\.html$ /index.php?keyword=$1 [R,NC,L]
But I have tried to get the end result so that the url in the address bar
is like this: http://www.example.com/compare/nikon.html
If I change it so that the rewritten url is in the address bar will the
variables still be passed and in instances where there is an anchor # tag
after the url will it still work?
Thanks for any help
You want to get rid of the R flag in your rule. That's causing the address bar to be changed to the original ugly looking URL.
Additionally, if you want to redirect the browser from the ugly to the nicer looking URL, you need a different rule. So something like:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+index\.php\?keyword=([^&\ ]+)
RewriteRule ^ /compare/%1.html? [L,R]
RewriteRule ^compare/([^/]*)\.html$ /index.php?keyword=$1 [NC,L]
I was wondering if I could get some help changing a URL.
I would like to change and match all city/state URL's to a different format and have them redirect to the newer URL if someone lands on them.
I would like to change and redirect:
http://www.domain.com/FL/Miami.html
to
http://www.domain.com/miami-fl/
The rule I have right now that I would like to change and redirect to new one:
RewriteEngine On
RewriteRule ^(.*)/(.*)\.html$ index.php?st=$1&city=$2 [L]
As long as the case doesn't matter, you can just do this:
RewriteEngine On
RewriteRule ^(.+)-([^/-]+)\.html$ index.php?st=$2&city=$1 [L]
I am sure this already exists, but I'm not too sure the terminology to search for exactly what I am looking for.
I have a url like http://www.example.com/members/$variable/achievements and I want all of these page to redirect to one level up, for example http://www.example.com/members/$variable.
I was originally using :
RewriteEngine On
RewriteRule ^members/([\w]*)/achievements/$ http://www.example.com [R=301,L]
which works fine for redirecting the original page to the homepage, but I would rather it go to that variable page.
RewriteEngine On
RewriteRule ^members/([^/]+)/achievements/?$ http://www.example.com/members/$1/ [R=301,L]
This assumes there is something after $variable/achievements (with and without the ending /) and redirect it back to http://www.example.com/members/$variable/
This is a page on my domain: www.mydomain.com/en/stats.php
I want it to look like this: www.mydomain.com/en/statistics/players
This is pretty simple to accomplish, but for some reason the htaccess code below doesn't work.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/statistics/players stats.php [R=301,L,QSA]
I get a 404 error when I try to open the SEO-friendly version. The page opens fine when I use the regular URL. What am I doing wrong?
The URL might not have a leading slash. Try without or optional slash. Additionally, you must check for the leading en, when you anchor your pattern at the beginning
RewriteRule ^/?en/statistics/players /en/stats.php
What worked in the end is the following:
RewriteRule en/statistics/players en/stats.php [NC,L]
I think it needs to be:
RewriteEngine On
RewriteRule ^en/statistics/players en/stats.php [QSA]
The R=301 means it will perform a redirect instead of a rewrite and try to redirect to /stats.php which doesnt exists I guess.
The L flag means that this is the last rewrite rule that will be processed for this request, which in this case I doubt is what you want. If there are rewrite rules further down for /en/stats.php they wont be processed.