I have this code in my htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ http://subdomain.example.com/index.php?id=$1 [L,QSA]
but everytime i go to something like http://subdomain.example.com/test/test
it should resolve to:
http://subdomain.example.com/index.php?id=test/test
which it does, but its changing my URL to be the above and its not keeping the original URL
Remove http:// from your target URL:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?id=$1 [L,QSA]
I have also corrected your regex in RewriteRule.
Related
I'm trying to append to wordpress an additional parameter into my URL.
For example, I have the URL: http://example.com
I want to change that to URL: http://example.com/this-example/
I'm thinking I can do this is in htaccess along the lines of a rewrite condition, but i'm unsure how to go about this. This is what I was thinking here.
Htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine on
RewriteRule ^/this-example/(.*)/ /index.php?$1 [L]
</IfModule>
Options -Indexes
You can try this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} !^/this-example [NC]
# use your own host here, for me is 192.68.10.10
RewriteCond %{HTTP_HOST} 192\.168\.10\.10$ [NC]
RewriteRule !^this-example/ /this-example%{REQUEST_URI} [L,R,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^this-example/(.*)$ $1 [L,QSA]
</IfModule>
Options -Indexes
I have the following URL
www.example.com/index.php?tag= xxx
I want to make it like the following using .htaccess
www.example.com/xxx
I done it with this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+?)/?$ /index.php?tag=$1 [L,QSA]
SO if I input this URL:
www.example.com/index.php?tag=1000
it be redirect to:
www.example.com/?tag=1000
if: www.example.com/1000 it works!
So I have dublicate URL and it's not good for seo.
How can redirect www.example.com/index.php?tag=1000 to www.example.com/1000
use this code for
.htaccess file
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+?)/?$ /index.php?key=$1 [L,QSA]
you index.php code will be
<?php
echo $_REQUEST['key'];
?>
then call
http://sitename.com/1000
output will be :1000
How can redirect www.example.com/index.php?tag=1000 to www.example.com/1000
You can insert this rule just below RewriteBase line:
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?tag=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
I need a URL like this:
http://domain.com/subfolder/file.php?src=quick-brown-fox&m=1&size=320x480
.. changed to:
http://domain.com/subfolder/file/quick-brown-fox/320x480
I updated the htaccess with:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/subfolder/([^\.]+)$ $1.php [NC,L]
but I'm getting a 404. What am I doing wrong?
You could do this in subfolder/.htaccess
Options -MultiViews
RewriteEngine On
RewriteBase /subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?(.*)$ $1.php [NC,L]
Then capture the URI in php.
You can have this rule in /subfolder/.htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /subfolder/
RewriteRule ^(file)/([^/]+)/([^/]+)/?$ $1.php?src=$2&m=1&size=$3 [QSA,NC,L]
i got a problem with rewriting my edit.php?id=1 to edit/id/1. Right now i have the following in my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^edit/id/([^/.]+)$ edit.php?id=$1 [NC]
This doesn't change the url. Can something see what i do wrong?
You need one additional rule to change the URL externally. This should be placed in root .htaccess:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/([^/]+)/edit\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1/edit/id/%2? [R=302,L,NE]
RewriteRule ^([^/]+)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L,QSA]
Give this a try and see how it works for you.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L]
</IfModule>
OR you can do this if you only have a couple of directories the same. The will go in the root .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(profiles|customers|test)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L]
</IfModule>
I have the following question. Let's say I have link like
http://localhost/test/index.php/admin
I have the following htaccess:
Options -MultiViews
Options +FollowSymLinks
Options -Indexes
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) $1$2 [R=301,NE,L]
What it does is simply remove index.php from the URL. However, when I enter url like this:
http://localhost/test/abc/blabla/index.php
It goes on an infinite loop. What I want is to do nothing when another index.php is met in the URL. How can I achieve this? Thanks!
Replace your code with this:
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /test/
RewriteCond %{QUERY_STRING} !(^|&)r(&|$)
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php(?:/(.*))?$ $1$2?r [R=302,NE,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!index\.php/).+)$ index.php/$1 [L,NC]