How can I redirect someone who types http://domain.com/+abc (this should only apply to alphanumeric characters with a preceding "+" sign) into the address bar to http://domain.com/abc without the preceding "+"?
Would I have to do this via .htaccess? And if so, how? Would it also require some REGEX?
I'd appreciate any help on this! Thank you :)
Yes, you can do it with .htaccess and it will require regex. Add these lines into yours .htaccess file:
RewriteEngine On
RewriteRule ^\+(.*) $1
This should work.
Related
I need to add Rewrite/Redirect statements in my .htaccess to redirect a specific url to a different .php page with masking. The goal is when someone hits:
www.mydomain.com/sandbox
i need it to go to:
server.mydomain.com/directoryname/phpprogram.php. But I need it to mask so the address bar will still show www.mydomain.com/sandbox
Appreciate any help with this. Thanks.
You can use mod-rewrite to maks your URLs.
The following rule in an htaccess file should do the trick :
RewriteEngine On
RewriteRule ^sandbox/?$ /directoryname/phpprogram.php [L]
This will internally map a request for example.com/sandbox to example.com/directoryname/phpprogram.php .
The /? in the regular expression pattern above matches the traling slash as an optional character so the rule will also match example.com/sandbox/ .
I am new in htaccess rules. I have tried to search about my question but couldn't get the answer.
I have got a url like this mysite.it/test/libro/la-missione-cristiana/1959 and I would like to rewrite to mysite.it/test/index.php?page=libro&id=1959
I have the following htaccess file in my root folder and I have added the following line:
RewriteRule ^test/libro/([^/.]+)/([^/.]+) test/index.php?page=libro&id=$2 [QSA,L]
but It doesn't work.
I would really appreciate if someone could explain me the cause.
Thank you,
your match all but slash group '([^/.]+)' appears to group all non-slash and non-any-character, thus it will not match anything as the . matches any, and the plus require at least one match.
try remove the dots
RewriteRule ^test/libro/([^/]+)/([^/]+) test/index.php?page=libro&id=$2 [QSA,L]
should work for you.
I need to remove the dynamic part of a url:
example.com/pagename/?btag=a_233b_230c_&affid=201
so remove everything after and including "?"
But I don't want this rule to apply to this directory:
example.com/wp-content/?attr=1345
Is it possible to do this with .htaccess?
Thanks, any help is appreciated
Jon
RewriteCond %{REQUEST_URI} !^/wp-content
That might help:-d just repeat for other folders.
I am curious why it cannot work and looking for a solution.
the following is in my htaccess
RewriteRule ^field/category/([a-zA-Z0-9\-]+)&([a-zA-Z0-9\-]+)$ field.php?cat[]=$1&cat[]=$2
This works well and the url will be domain.com/field/category/Ball&Drinks
How can I change the & to - and make it become domain.com/field/category/Ball-Drinks
I try
RewriteRule ^field/category/([a-zA-Z0-9\-]+)-([a-zA-Z0-9\-]+)$ field.php?cat[]=$1&cat[]=$2
and it doesn't work. The - character is not taken as a literal. Anyone can help? Thanks.
You have to escape the - character:
RewriteRule ^field/category/([a-zA-Z0-9\-]+)\-([a-zA-Z0-9\-]+)$ field.php?cat[]=$1&cat[]=$2
I know this is an old question but I just spent an hour figuring this out so I figured I should share the answer:
Replace the hyphen with [\-] to get the RewriteRule to treat it as a string literal.
So final code would be: ^field/category/([a-zA-Z0-9\-]+)[\-]([a-zA-Z0-9\-]+)$ field.php?cat[]=$1&cat[]=$2
Hi I'm not a programmer by any stretch of the imagination and am trying to do a multi 301 redirect in my htaccess file based on the following:
So I have a ton of urls all with similar naming conventions - here is a sample of 2.
http://www.hollandsbrook.com/garrett-at-gold/
http://www.hollandsbrook.com/garrett-ace-250/
These urls need to redirect to:
http://www.hollandsbrook.com/garrett-metal-detectors/garrett-at-gold/
http://www.hollandsbrook.com/garrett-metal-detectors/garrett-ace-250/
I could just redirect them 1 line at a time, but I'd like to use regex.
Here's what I was thinking so far but not working:
RewriteRule ^garrett-([a-z])/$ /garrett-metal-detectors/$1/ [R]
Basically i need to redirect any page right off the root that starts with "garrett-" to include the folder path of "garrett-metal-detectors".
Any thoughts would be MUCH appreciated. Many thanks in advance for your help.
if you want temprorary redirect use:
RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=302,L]
if you want permanent redirect use:
RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=301,L]
I'm am not an expert on Regular Expressions, but looks like your reg ex may be a bit off...
try:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^((garrett)(-[a-z0-9]).*)/$ /metal-detectors/$1/ [R]
This is looking fro anything starting with "garrett" followed by any letter/number/hyphen combo.
Note: having "garett" in the destination part give you a loop of redirects, so you may have to choose a different word, or remove it all together...