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]
Related
My .htaccess looks like this..
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [R,L]
</IfModule>
I want to be able to redirect an URL that looks like this..
https://sub.domain.com/ZTHF76
to...
https://www.domain.com/members/invite/ZTHF76
But instead I am getting
https://www.domain.com/members/invite/index.php
I need to keep the first rule to remove index.php from the URI of the rest of the application.
Any help with this greatly appreciated.
You should reorder your rules and keep redirect rule before rewrite one:
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
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 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.
I am trying to rewrite:
mydomain.com/category.php?id=cat
to
mydomain.com/cat
I have used the following .htaccess code but it keeps showing a 505 error:
RewriteEngine On
RewriteRule ^([^/]*)$ /category.php?id=$1 [L]
I read on another page that it is because the page keeps looping, but I can't work out how I can fix the code.
Keep your rule like this:
RewriteEngine On
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /category.php?id=$1 [L,QSA]
Try this.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)/ category.php?id=$1 [L]
</IfModule>
You need to add RewriteCond to avoice rewrite for category.php
RewriteEngine On
RewriteCond %{REQUEUST_URI} !^ /category.php/(.*)
RewriteRule ^(\w+)/ category.php?id=$1 [L]
Ok this should work:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/category.php
RewriteRule ^(.*)$ category.php?id=$1 [R=301,L]
Demo: http://ht6.valhook.com/cat
I am quite new to mod rewrite and i have this, which is not working.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /kitnes/cache/dynamic/$1.htm
RewriteRule /kitnes/cache/dynamic/([^/\.]+).htm index.php?id=$1 [NC,QSA,L]
the rewritten URL is something like this http://www.ghananewsportal.com/1.1629334 and i would like it to redirect to http://www.ghananewsportal.com/?id=1.1629334 if the rewritten URL fails.
thanks.
Something like this should work:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/kitnes/cache/dynamic/$1.html -f
RewriteRule ^(.+)$ /kitnes/cache/dynamic/$1.htm [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?id=$1 [QSA,L]