htaccess redirect to subfolder with same path attached? - mod-rewrite

How can I go about redirecting my old URLs which would have been: http:// blah.com/some/post/name
to the new URLs which would be: http:// blah.com/new/some/post/name
Is this even possible?
I don't want to simply redirect any requests for the blah.com domain to blah.com/new
I want to make sure the subpath is still attached to the redirect

it should be possible.
Try to put this in your .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/some\/?
RewriteRule (.*) /new/$1 [R=301]
</IfModule>
Try it out and let me know - I haven't had time to test it very thoroughly.

Related

mod_rewrite how to transfer root to specific file

i am using smarty framework and the urls are dynamic build with master-layout index file.
i want to make a mod_rewrite rule to transfer the url
www.mysite.com to /mysiteSubfolder/member/index.php
No redirect, just to map the urls to those calls, for the sake of SEO friendly url.
www.mysite.com/home.html works as desired but the root url not working.
i tried the following but it just stays on root url's index file root/index.php
here is my current .htacces code
Options -Multiviews
Options -Indexes
RewriteEngine On
RewriteRule ^$ /mysiteSubfolder/client/index.php (not working)
RewriteRule ^home.html$ /mysiteSubfolder/client/index.php (working)
Your root .htaccess, ie, /.htaccess, but not in /mysiteSubfolder/client/.htaccess, should be like this (TESTED on Debian/Apache2):
Options -Multiviews
Options -Indexes
RewriteEngine On
RewriteRule ^$ /mysiteSubfolder/client/index.php [L]
RewriteRule ^home.html$ /mysiteSubfolder/client/index.php [L]

Escaped Fragment Redirect htaccess

my website (thedutchtilt.com) employs AJAX.
Now I know that whenever Google tries to crawl a page, e.g. #!stories/component_74511, it will turn that url into thedutchtilt.com/?_escaped_fragment_=stories/component_74511 .
My question is, how do I format a htaccess redirect so that the aforementioned site will map to the other one?
I've tried
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=stories/component_74511
RewriteRule ^$ http://www.thedutchtilt.com/full.html? [R=302,L]
but trying this just gives http://thedutchtilt.com/?_escaped_fragment_=stories/component_74511, which is my homepage.
I'm really confused now, and nothing seems to be working (sigh).
Kartik
Current .htaccess:
RewriteEngine on
RewriteOptions inherit
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RedirectMatch ^/$ /index.html
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=stories/component_74511
RewriteRule ^$ thedutchtilt.com/full.html? [R=302,L]
Thanks for providing .htaccess code. Problem is your this RedirectMatch line:
RedirectMatch ^/$ /index.html
Comment it out and try again. index.html should be loaded as default using this DirectoryIndex directive:
DirectoryIndex index.html

Mod rewrite apache - rewriting only base url

I'd like to rewrite
www.site.com/a/b/?param1=one&param2=two
in
www.site.com/c/d/e/?param1=one&param2=two.
Where www.site.com/a/b does not exists. I tried with
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^a/b/(.*)$ www.site.com/c/d/e/$1 [QSA,L]
What's wrong with it?
Try this one:
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^/a/b/(.*)$ /c/d/e/$1 [QSA,L]
There is no need for adding the incompleate domain. If you want that the users visit a second domain you have to add the R option and the protocol. For a redirect to a second domain try this:
RewriteRule ^/a/b/(.*)$ http://www.site.com/c/d/e/$1 [R,QSA,L]

Changing uri_protocol to PATH_INFO breaks my CodeIgniter app?

I'm setting up Haughin's Twitter OAuth Library for CodeIgniter, and one requirement is to change the uri_protocol in config.php to PATH_INFO, which seems to be breaking my app in the way that all requests load the home controller (ex. Navigating to http://dev.myapp.com/login would normally take my to the Login controller, but it's just showing the default controller.)
Any ideas what would be causing this, or maybe an Apache2 configuration that's messed up?
Its to do with URL rewrites. Check your .htaccess files to see if you have the correct rewrite rules. Here is something that works for me when using PATH_INFO.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
The above should work for you without any modification. If you're hosting in a folder lets say like http://myserver.com/my_app/ then change /index.php to /my_app/index.php in both places.

Mod Rewrite Newbie in CodeIgniter

I'm pretty new to mod-rewrites, and I'm having trouble getting this right:
I'd like http://myurl.com/special and http://www.myurl.com/special to both redirect to http://myurl/index.php/special without changing the url for the visitor in their browser.
currently, my .htaccess looks like this, to remove www from URLs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.myurl.com [NC]
RewriteRule ^(.*)$ http://myurl.com/$1 [L,R=301]
</IfModule>
I tried a bunch of different things to redirect the special URL, but nothing has worked for me so far, each with a different undesirable result. Please let me know if you have an idea about what I can add here!
I tried this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^special$ /index.php/special$1 [NC]
RewriteCond %{HTTP_HOST} ^www.myurl.com [NC]
RewriteRule ^(.*)$ http://myurl.com/$1 [R=301]
</IfModule>
That makes http://myurl.com/special redirect to the default controller, and makes http://www.myurl.com/special redirect to http://myurl.com/index.php/special AND changes the url in the browser. Neither of those is quite right, although the second is closer to what I need.
oh no you don't need htaccess to do that just use CI's routes. Here first change your HTACESS to this:
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
This one is way way better and you never have to change it for anything not for img folders or anything just leave it pure. now for your issue.
open routes php in the Application->config folder.
Now in CI all files route through index.php by default so i am assuming you mean your default controller anyway to route "controllers" like in your case special back to the main site just do this:
if your default controller is still "welcome" as it is downloaded you would write a route like this:
$route['special/(:any)'] = "welcome";
your url will not change and everything will be perfect
BUT DONT STOP READING YET, JUST TO MAKE SURE.
this is what your routes would look like after your done:
//these two are for CI
$route['default_controller'] = "welcome";
$route['scaffolding_trigger'] = "";
//this is your route sending all and any traffic for special
//no matter how many levels it will always go to welcome->index.
$route['special/(:any)'] = "welcome";
//if you want to use sub-pages or other functions within your welcome controller
//i.e. welcome->signup. then just send the route information to the controller like this:
$route['special/(:any)'] = "welcome/$1";
The routing class in php is very powerful and this is just a piece here for more detailed info on routing see this page:
CodeIgniter User Guide -> URI Routing
Really hope i haven't confused you more. Good Luck
Assuming www.myurl.com and myurl.com are both set-up as ServerAliases in your VirutalHost, then something as simple as...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Resources