I'm trying to figure out how to redirect all image urls like this:
https://example.com/images/FILE.PNG
to this:
https://example.com/old-site/images/FILE.PNG
Is there an easy way to do this with .htaccess? I've looked around, but couldn't find a post anywhere with a similar scenario of adding a sub directory and don't understand htaccess rules well enough to write it myself.
Any and All help is appreciated!
Using URL Rewrite in .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/?images/(.*)$ /old-site/images/$1 [R=301,L]
You can use this one-liner rule in your root .htaccess:
RedirectMatch 301 ^(/images/.+)$ /old-site/$1
Related
I have problem with mod_rewrite rule.
I'm trying to get adress:
www.site.com/en/page.html
from url
index.php?page=page&lang=en
I've tried a couple of hours and I can not get ... Unfortunately, I do not know at all mod_rewrite ...
Can someone a guiding me to a solution?
-
Peter
First, make sure mod_rewrite is enabled in your Apache configuration file.
Also, make sure htaccess files are allowed (AllowOverride All for your document root folder).
Then, put this code in your htaccess (which has to be in document root folder)
RewriteEngine On
RewriteRule ^([a-z]{2})/([^/]+)\.html$ /index.php?page=$2&lang=$1 [L]
This rule allows you to reach any language/page, for instance:
http://domain.com/en/page.html --> /index.php?page=page&lang=en
http://domain.com/fr/something.html --> /index.php?page=something&lang=fr
If you want to restrict lang parameter:
For english only
RewriteEngine On
RewriteRule ^en/([^/]+)\.html$ /index.php?page=$1&lang=en [L]
For english and french (as an example)
RewriteEngine On
RewriteRule ^(en|fr)/([^/]+)\.html$ /index.php?page=$2&lang=$1 [L]
Thank you for your help - exactly is what I meant.
Roughly already beginning to understand what's going on...
From the documentation at hand I can handle it :)
-
Peter
I have a slight issue. I have configured my default controller as :
c$route['default_controller'] = 'news';
so when I point my browser to http://localhost/mysite all the news get loaded as instructed by the news controller.
Now on this page, I have given links to "read article" to read the full article. For this I have to point my browser to http://localhost/index.php/news/view/news-slug. I want to remove index.php from the url. I had already tried re-routing using wildcard without any success. Can you tell me how to do that?
There is a documentation on removing the index.php from the URL if you are using Apache with it's mod_rewrite:
Removing the index.php file
Using the following rewrite code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Also, there are many similar questions to yours, have a look at these questions from the search:
Search query on removing index.php in Codeigniter
You need to define your .htaccess file for this. Check this wiki: http://codeigniter.com/wiki/mod_rewrite
I have link www.mydomain.com/page.php?pageid=10
I want to change into www.mydomain.com/10
please help me this guys.
Put this in a .htaccess file, and place it in the webroot.
RewriteEngine On
RewriteRule ^([0-9]+)$ page.php?pageid=10
I need to do a mass 301 Redirect for all pages ending with .html for my site. I am looking to move all the old .html files to a sub-folder ir.
RedirectMatch 301 (.*)\.html$ http://www.domain.com/folder/$1.html
When I add this and refresh the browser I get a ton of folder/folder/folder now after the url ie
domain.com/folder//folder/folder/folder.....
Any ideas what could be wrong?
Thanks if you can help
The problem is, that 'folder/foo.html' also matches the condition of the RedirectMatch and folder is appended again (and again, and again ...)
Therefore you probably need something like this (untested):
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*)\.html$ /folder/$1.html [R=301,L]
The RewriteCond should check that the URI doesn't start with /folder and only if this condition is met, the RewriteRule will be checked.
Unfortunately I haven't any Apache installation available at the moment for testing such things, so you will probably have to try it on your own. But I hope you got the idea.
If your old html files are in the root, I would suggest the following:
RedirectMatch 301 ^([^/]+)\.html$ http://www.domain.com/folder/$1.html
In order to convert dynamic URLs on my site www.kitesmovie.co.in to static urls. Eg: www.kitesmovie.co.in/stories.php?id=10 to www.kitesmovie.co.in/Barbara_Mori_Hrithik_Roshan_New_Movie.
I tried using rewriting rules in my htaccess files, but it did not work. Please tell me how to do this.
Thanks a lot in advance.
It's not really clear what you are trying to achieve.
When you say "convert dynamic urls to static urls", do you really want to have user to type in the ...?id=10 and the file named Barbara_Mori_Hrithik_Roshan_New_Movie lives on your server? I think, it's the opposite way - you want to let the user type in the long & nice title and actually resolve it to ?id=10
If this is the case, the #Mike's answer is nearly correct, you only have to swap the parts of the last line:
RewriteRule Barbara_Mori_Hrithik_Roshan_New_Movie stories.php?id=10 [R,L]
Another question - are you sure you have the .htaccess working? An easy way to check is to set the contents of .htaccess to
order deny, allow
deny from all
And see if you can still access that directory. If you can, this means the "deny from all" does not work. Then check your apache config - is .htaccess allowed in the particular virtualhost and/or directory.
Lots of missing info there. If you are using apache with mod_rewite installed, place this in your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule stories.php?id=10 Barbara_Mori_Hrithik_Roshan_New_Movie [R,L]
</IfModule>
You might want to have a look at this article: http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/
Generally, you would use a RewriteRule something like this:
RewriteRule ^stories.php?id=10$ Barbara_Mori_Hrithik_Roshan_New_Movie [R=301,L]
If that's not working for you, then feel free to add more details to your question.