i want to rewrite url like:
http://domain.com/index.php/subdirectory/subdirectory/
to:
http://domain.com/index.php
My rewrite rule look like this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)
RewriteRule ^(.*)$ index.php$ [L]
thanks,
The RewriteCond
RewriteCond %{REQUEST_URI} !(.*)
will always been false, you don't need it. Just use :
RewriteEngine On
RewriteRule ^(.*)$ index.php [L]
Related
I would like to redirect my pages in the following ways:
www.example.com/index.cfm?locale=it -> www.example.com/it
and I would like to access the same page when I type:
www.example.com/it
I wrote an htaccess file but it causes a redirect loop. Here is the file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#REWRITE RULES
#---------------------
RewriteCond %{QUERY_STRING} ^locale=(it|en|fr|de|es)$
RewriteRule ^index\.cfm$ %1? [R=302,L]
RewriteCond %{REQUEST_URI} !^index\.cfm
RewriteRule ^(it|en|fr|de|es)/?$ index.cfm?locale=$1 [L]
</IfModule>
Could you help me to resolve it?
Thanks!!!
You can try it this way.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
Rewrite ^ - [L]
RewriteCond %{THE_REQUEST} ^GET\ /index\.cfm\?locale=(it|en|fr|de|es)
RewriteRule ^ %1? [R=302,L]
RewriteRule ^(it|en|fr|de|es)/?$ index.cfm?locale=$1 [L]
Try this:
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com/it[nc]
RewriteRule ^(.*)$ http://www.example.com/it/$1 [r=301,nc]
//301 Redirect Old File
Redirect 301 www.example.com/index.php?locale=it www.example.com/it
//301 Redirect Entire Directory
RedirectMatch 301 www.example.com/index.php?locale=it(.*) www.example.com/it/$1
This is my .htaccess file:
Options -Indexes
RewriteEngine on
RewriteCond $1 !^(index\.php|css|images|jscript|user_guide|login|en|favicon.ico|uploads|script.php)
RewriteRule ^(.*)$ index.php/$1 [L]
And I want to be able to type this adress directly:
mysite.com/system/application/views/req-php.php?_INPUT&f=xxx
You can add another negative RewriteCond to avoid rewriting for this new URL:
Options -Indexes
RewriteEngine on
RewriteCond %{THE_REQUEST} !\s/system/application/views/req-php\.php\?_INPUT&f= [NC]
RewriteCond $1 !^(index\.php|css|images|jscript|user_guide|login|en|favicon.ico|uploads|script.php)
RewriteRule ^(.*)$ index.php/$1 [L]
I'm hoping someone can assist me with a mod_rewrite rule to redirect dynamic urls pointing to "videos.php" on my server to the base url.
For example, I need to redirect 'website.com/1/music/various/videos.php?=1234'
to 'website.com/videos.php?=1234'
edit: I am looking for a dynamic solution. If a url is pointed to videos.php at any time, I need to do a 301 redirect to home directory. Ie if /1/home/music/videos.php?=1234 redirect to /videos.php?=1234, or /music/playlist/1234/videos.php?1432 to /videos.php?1432.
Create a .htaccess file and insert these lines:
RewriteEngine On
# Page moved permanently:
RewriteRule ^videos\.php\?\=([0-9]+)\.html$ /1/music/various/videos.php?=$1 [R=301,L]
When testing, leave out the R=301, part, or you'll only see cache contents for a long, long time. Add it when sure its working fine. Or use 302, which means temporarily.
Please check this:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/1/music/various/videos.php$
RewriteCond %{QUERY_STRING} (.+)$
RewriteRule ^(.*) /videos.php [R,QSA]
RewriteCond %{REQUEST_URI} ^/videos.php$
RewriteCond %{QUERY_STRING} !(.+)$
RewriteRule ^(.*) http://%{HTTP_HOST}/ [R=301]
If it's not work, then try this:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/1/music/various/videos.php$
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(.*) /videos.php%1 [R]
RewriteCond %{REQUEST_URI} ^/videos.php$
RewriteCond %{QUERY_STRING} !(.+)$
RewriteRule ^(.*) http://%{HTTP_HOST}/ [R=301]
I would like to change urls from:
http://subdomain.domain.com/page/ to http://subdomain.domain.com/?page=pagename
and also:
http://domain.com/page/ to http://domain.com/?page=pagename
though haven't had much success.
Here is my htaccess file so far [updated]
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Remove 'www'
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Add slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://resolutiongaming.com/$1/ [L,R=301]
# Subdomain redirect
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
I used RewriteRule ^([a-zA-Z]+)/$ ?page=$1 which seemed to work for the domain url but not the subdomain. Any help would be appreciated.
Actually had to do something like this recently. Try this for your Subdomain redirect block:
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$2 [R=301,L]
Or maybe this; note the change from $2 to $1:
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
EDIT: Or Maybe try this. Note that you need to capture two parts of the URL to rewrite as you are explaining. Each item in parenthesis ( and ) corresponds to a string in the rewrite. Try this. Using your nicer regular expression RewriteRule as you mention in the comments:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/$2 [R=301,L]
Or maybe this:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/page=$2 [R=301,L]
So it was an easy fix really. I basically put a .htaccess file in each subdomain directory that looks like this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
Hope this helps someone. :D
I've this url: http://www.test.com/page.php?k=m1ns
and I want this one: http://www.test.com/r/m1ns
My .htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^k/([^/\.]+)/?$ page.php?k=$1 [L]
# force www. in all requests
RewriteCond %{HTTP_HOST} ^test\.com [NC]
RewriteRule ^(.*)$ http://www.test.com/$1 [L,R=301]
# enable hiding php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
But it doesn't work. Only the non-www -> www and hiding php rules works.
If I put http://www.test.com/page.php?k=m1ns does not rewrite.
Anyone knows why?
Thanks.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^r/([^/]*)$ /page.php?k=$1 [L]
On your top page.php
if (strstr($_SERVER['REQUEST_URI'], '/page.php?k=' . $var . '')) {
header("HTTP/1.1 301 Moved Permanently");
header("location:http://www.test.com/r/" . $var );
exit();
}
Try this
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^r/(.*)/ /page.php?k=$1 [L]
It should work regardless of whether or not www is entered.