I have a url like
domain.com/order/index.php?q=
the order folder no longer exists as its been changed to ecom, so it now looks like the below.
domain.com/ecom/index.php?q=
The problem is we have a ton of external links wanting the order url some scripts and images pull from this url, etc.
How can I simply set .htaccess to still allow the order directory.
I tried this
RewriteRule ^order/(.*)$ /ecom/$1 [L]
It works only if it exactly matches order (e.g domain.com/order/ , but anything after order it then breaks (e.g domain.com/order/index.php?q=)
Any help would be appreciated. I just keep seeing examples similar to what I have above so not sure if I am doing something wrong here.
Use QSA flag
RewriteRule ^order/(.*)$ /ecom/$1 [QSA,L]
you can do a permanent redirect to a page
RewriteRule ^url-string-to-redirect$ http://www.yourdomain.com/your-new-url-string [R=301,L]
Related
Here are some examples of the old URLs:
http://www.test.com/files/Old_Name.zip
http://www.test.com/files/Old_Name.php
http://www.test.com/files/Old_Name_Setup.php
http://www.test.com/files/Old_Name_100_Setup.php
Here are what the new URLs look like:
http://www.test.com/files/New_Name.zip
http://www.test.com/files/New_Name.php
http://www.test.com/files/New_Name_Setup.php
http://www.test.com/files/New_Name_100_Setup.php
I need to edit my .htaccess file to reflect these changes, so when people visit the old URLs, they are taken to the new URLs.
I've seen something like
Redirect 301 /files/Old_Name.php http://www.test.com/files/New_Name.php
Unfortunately, this way would require me to do this for every single file, and there are a lot. I'm guessing I'm going to have to use regex, but I haven't seen a solution online that only modifies part of the filename. I'm assuming this should be able to be done in 1 line as the structure change between old and new URLs is consistent.
You can use in /files/.htaccess:
RewriteEngine on
RewriteRule ^Old_Name(.*)$ New_Name$1 [NC,L,R=301]
Or in root .htaccess:
RewriteEngine on
RewriteRule ^files/Old_Name(.*)$ files/New_Name$1 [NC,L,R=301]
I would like to restructure some folders on my website, specifically I am want to move what's contained inside "images/" to "images/gallery/", but I don't want to break previous links, so I thought of using htaccess.
I looked up several tutorials and even several questions here on stackoverflow, tried several times, but I can't get the rewrite rule to work.
This is what I have:
RewriteRule ^images/(.*) /images/gallery/$1 [R=301,NC,L]
But when I try to access anything inside /images/ (for example images/test.jpg) it stays into images/test.jpg and doesn't go to images/gallery/test.jpg. So it doesn't seem to have an effect.
Any clue on what I might possibly doing wrong?
Thank you!
Your rule at present will cause a redirect loop since /images/ is present in both source and target URLs and you're not even using anchor $:
You can tweak your regex like this:
RewriteRule ^images/([^/]+)$ /images/gallery/$1 [R=301,NC,L]
Now pattern will match /images/test.jpg but won't match redirected URL /images/gallery/test.jpg due to use of [^/]+ in pattern.
Make sure this rule is first after RewriteEngine On and there is no .htaccess in /images/ folder.
EDIT: If your original path has sub-directories also then use:
RewriteRule ^images/((?!gallery/).+)$ /images/gallery/$1 [R=301,NC,L]
I have the following in my htaccess:
RewriteRule ^news/[a-zA-Z0-9-_]+?/(.+)$ /news [R=301,L]
This works how I want it to, for example if I go to /news/some-category/some-post it just redirects to /news which is great. However it is also affecting my uploads folder. Take the following URL for example:
/news/wp-content/uploads/2014/07/Emily-286x300.jpg
This gets redirected to /news as well so all my images are broken. Is there a way to tweak this rule so that it doesn't affect the wp-content/uploads directory?
If /news/some-category/some-post represent a 3-level subdirectories, you can use this rule
RewriteRule ^news/[^/]+/[^/]+/?$ /news [R=301,L]
Also, please note you'll have to clear your browser's cache before trying again such link /news/wp-content/uploads/2014/07/Emily-286x300.jpg (my rule will not match it but your last rule does and it's in browser's cache)
We have a website where we show clients creative work we have produced for them. We upload raw assets to a path like this:
x.com/clients/clientName/campaignName/size/
I have a PHP script which adds our branding, contact information and other information and pulls in the raw creative (usually a swf object). It is in this directory x.com/clients/index.php and it accepts a query string parameter ?path so it knows where to look for the creative.
I am trying to do an apache rewrite in .htaccess so that our designers can upload directly to the known folder structure but so that when you go to x.com/clients/clientName/campaignName/size/ it should rewrite to x.com/clients/index.php?path=clientName/campaignName/size/
I am currently using the following rewrite rule, which works for the first folder level e.g. x.com/clients/clientName/ does successfully rewrite, but any subsequent folders do not.
RewriteRule ^clients/([^/\.]+)/?$ /clients/index.php?path=$1 [L]
My RegEx's are terrible, so I'm stuck on what to do. Any help appreciated, thank you kindly.
Your regex is only matching urls like clients/xxxxxx/ because your pattern [^/\.]+ means one or many characters except "/" or "."
With your rule, it can't work for other subdirectories.
You can change your rule by this one
RewriteRule ^clients/(.+)$ /clients/index.php?path=$1 [L]
To avoid internal server error (code 500 which means an infinite loop in this case), you can do it this way
RewriteRule ^clients/index\.php$ - [L]
RewriteRule ^clients/(.+)$ /clients/index.php?path=$1 [L]
Is there a special reason you want to use regex? In my opinion you can just catch everything coming after /clients:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^(.*/)?index\.php$ [NC]
RewriteRule ^clients/(.*)$ /clients/index.php?path=$1 [L]
The second line is to prevents redirect loops, because the index.php is also in the folder /clients and this would cause never ending redirects.
I am using Apache.
I have www.example.com/?p_action=user_profile&post_author=34 and I want to use www.example.com/niceurl/
I want that if user enters any of the urls, the www.example.com/niceurl/ is shown in his browser (of course, www.example.com/?p_action=user_profile&post_author=34 is actually retrieved from the server).
RewriteRule does not seem to be the solution for this, does it?
Thanks
Well you can try putting,
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /?p_action=$1&post_author=$2 [L]
In your .htaccess file.
IMO RewriteRule should solve your problem.