I would like to know how to URL change /index.php?u=xx&p=yy to /xx/yy/.
index.php will be removed and u and p values become with a slash mark.
htaccess code:
RewriteCond %{THE_REQUEST} /index\.php[\s?/] [NC]
RewriteRule ^(.*?)index\.php(/.*)?/?$ /$1$2 [L,R=301,NC,NE]
I have used the above code but it only removes index.php. Others are remaining the same.
With your shown samples/attempts, please try following htaccess rules. Please make sure to clear your browser cache before testing your URLs.
Also please make sure that your htaccess rules file and index.php files are in same directory.
RewriteEngine ON
##External redirect rules as follows:
RewriteCond %{THE_REQUEST} \s/p/index\.php\?u=([^&]*)&p=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite rules as follows:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/(.*)/?$ index.php?u=$1&p=$2 [QSA,L]
Related
How can I do the following on the localhost which will be hosted later online:
I have this link:
http://localhost/shops/shop.php?c=15
I want to rewrite it to http://localhost/shops/shop/15
htaccess is(which is placed in C:\wamp\www\shops folder):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?RECIPES/(.*?)/?$ /single-product-details.php?=$1 [L]
RewriteRule ^/?SHOP/(.*?)/?$ /shop.php?=$1 [L]
With your shown samples, please try following Rules. Place your htaccess file along with shops folder(not inside it).
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /shops/
##External redirect to friendly url.
RewriteCond %{THE_REQUEST} \s/shops/(shop)\.php\?c=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite to actual url/files.
RewriteRule ^([^/]*)/(.*)/? $1.php?c=$2 [QSA,L]
I'm here to ask for advice about the .htaccess file that I can't configure as I would like.
I have a site, let's say :
www.mysite.com/php/blog.php
I would like the visitor to see in the address bar only:
www.mysite.com/blog
This is what the .htaccess file contains:
Options +FollowSymlinks
Options All -Indexes
RewriteEngine On
RewriteRule ^$ index.php #This line is to hide index.php on the home page, maybe it's not the right way to do it
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^php/([0-9a-zA-Z]+).php$ $1 [L] #I tried to write this, but it doesn't work
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I suspect that this question has been asked many times, but I have really tried, without success.
Can you help me, please?
Thanks !
Your patter is wrongly expecting URI to start with /php/ which is not the case here. Also keep http -> https rules at top and then handle .php extension rule like this:
RewriteEngine On
# http -> https redirect
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# To externally redirect /php/file.php to /file
RewriteCond %{THE_REQUEST} \s/+(?:php/)?(\S+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# To internally forward file to /php/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/php/$1.php -f
RewriteRule ^(.+?)/?$ php/$1.php [L]
URL is rewritten using following rule.
RewriteEngine on
RewriteRule ^([a-zA-Z]+)/$ category?id=$1
to change
http://localhost/newsite/category?id=home
to following structure
http://localhost/newsite/home/
Now I tried to redirect, newsite/category?id=home to newsite/home/, to make clean URL using redirect rule, such as 301, redirect, but it doesn't work.
You can use this set of rules in newsite/.htaccess:
RewriteEngine on
RewriteBase /newsite/
RewriteCond %{THE_REQUEST} /category(?:\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/$ category.php?id=$1 [L,QSA]
You missed the .php in the rewrite statement
RewriteRule ^([a-zA-Z]+)/$ category?id=$1
change to
RewriteRule ^([a-zA-Z]+)/$ category.php?id=$1
I want to redirect pages like:
/category-name/post-name.html?id=1234
To:
/category-name/1234-post-name.html
How can do this using htaccess?
What I have tried:
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^([^/]+)/([^.]+)\.html$ /$1/%1-$2\.html [L,R=301]
But it is a continuous redirect.
You can use these rules in your site root .htaccess:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+([\w-]+)/([\w-]+)\?id=([^\s&]+) [NC]
RewriteRule ^ /%1/%3-%2? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^([\w-]+)/([^-]+)-([\w-]+)/?$ $1/$3?id=$2 [L,QSA]
Try this
Make sure the url is root url
Example:-
www.foo.com/category-name/post-name.html
It will only work if the project url is same as that of the above.
www.foo.com/blog/category-name/post-name.html
This won't work you need to update the RewriteBase url accordingly l.
This is the conditions
RewriteEngine On
RewriteBase /
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule here
RewriteRule ^category-name/([0-9]+)-post-name$ /category-name/post-name.html?id=$1 [L]
This should work..
I am working on a website that uses DokuWiki and the website is called MiscWiki.
Currently all of the URLs are structured this way
http://www.miscwiki.org/doku.php/something/something
I would like to use a .htaccess rewrite to remove the doku.php from the URL. I currently have this statement but it is not working.
RewriteRule ^([^/]+)/doku.php/?(.*)$ /$1 [R=301,L]
Thank you for the help on this one.
You can use these rules in your site root .htaccess:
AcceptPathInfo On
RewriteEngine On
## Uncomment next 2 lines only when you want to remove doku.php/ from old links
#RewriteCond %{THE_REQUEST} \s/+doku\.php/(\S*) [NC]
#RewriteRule ^ /%1 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ doku.php/$0 [L]