i'm searching for rule for change link in htaccess.
Currently the link looks like this:
localhost.com/forum/profile.php?id=1
And this is the effect I would like to achieve:
localhost.com/forum/profile/1
I added the following rules:
Options -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/forum/profile\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /forum/profile/%1? [R=301,L]
The problem is that the page automatically redirects to the expected link, but a 404 error is returned
You need one more rule to map forum/profile/123 to forum/profile\.php?id=123. Please clear your browser cache before testing your URLs.
Options -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/forum/profile\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /forum/profile/%1? [R=301,L]
RewriteRule ^forum/profile/([0-9]+)/?$ /forum/profile.php?id=$1 [NC,QSA,L]
Related
I have URLs like http://url.com/top_admin/order.php?do=view&oid=124 and
I need to rewrite it to http://url.com/top_admin/order/view/124 , where
top_admin is a folder that contains my script.
this is my code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^order/(.*)/([0-9]+) order.php?do=$1&oid=$2 [L]
but it does not work.
With your shown samples/attempts, please try following. Please make sure to clear your browser cache before testing your URLs.
Options +FollowSymLinks -MultiViews
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(top_admin/order)\.php\?do=([^&]*)&oid=(\d+)\s [NC]
##Rule for external rewrite with 301.
RewriteRule ^ /%1/%2/%3? [R=301,L]
##Rule for internal rewrite to .php file.
RewriteRule ^([^/]*)/([^/]*)/(.*)/?$ $1.php?do=$2&oid=$3 [L]
I am trying to make a link that looks like https://www.exapmle.com/profile.php?u=8 to look like https://www.exapmle.com/profile/8
I have a tried variations of this in htaccess:
RewriteRule ^/profile/([0-9]+)/?$ profile.php?u=$1
RewriteRule ^/profile/([0-9]+)\.html /profile.php?u=$1
I don't know what i am doing wrong, the links don't change and I'm not getting any errors either
You may use this code in your site root .htaccess:
Options -MultiViews
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /profile\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /profile/%1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^/?profile/(\d+)(?:\.html)?/?$ profile.php?u=$1 [L,QSA,NC]
I need to be able to rewrite http://example.com/staging/details/?postid=23 so that it becomes http://example.com/staging/grandhotelterduin
I am not sure how the .htaccess rule should be?
I have came up with something like this
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^grandhotelterduin/(.*)$ ./details/?postid=23 [L,NC]
I am not sure I am doing this correctly, can you plz help
I want it such that the http://example.com/staging/grandhotelterduin/ get redirected to http://example.com/staging/details/?postid=23 but the url that appears in the browser is `http://example.com/staging/grandhotelterduin
Use this:
RewriteEngine On
RewriteRule ^grandhotelterduin$ /staging/details/?postid=23 [L]
It will give you the following URL:
http://sheetz.nl/grandhotelterduin
EDIT:
RewriteCond %{THE_REQUEST} /staging/details/?postid=([0-9]+) [NC]
RewriteRule ^ /staging/grandhotelterduin [L,R]
I have a link like this:
/add.php?id=50&link=page2
I want it to redirect to this:
/add/50/page2
How can I do this? I tried the following, but it did not work:
Redirect /add.php?id=50&link=page2 /add/50/page2
You can use this code in your DOCUMENT_ROOT/.htaccess file:
Options -MultiViews
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /add\.php\?id=([^\s&]+)&link=([^\s&]+) [NC]
RewriteRule ^ add/%1/%2? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^add/([^/.]+)/([^/.]+)/?$ add.php?id=$1&link=$2 [L,QSA,NC]
This is my .htaccess code to rewrite clean url.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+download\.php\?id=([^\s&]+) [NC]
RewriteRule ^ download/%1? [R=301,L]
RewriteRule ^download/([^/]+)/?$ download.php?id=$1 [L,QSA]
This code works fine for single parameter in url. For example it rewrites www.mysitename.com/download.php?id=123 to www.mysitename.com/download/123
But when I tried to pass multiple parameters in url, all I got are errors. Searched various resources and related questions but didn't got proper solution.
I need a url like www.mysitename.com/download/123/file-name instead of www.mysitename.com/download.php?id=123&name=file-name
I guess I've to use something thing like this RewriteRule ^(.*)/(.*)$ download.php?id=$1&name=$2. But while implementing I'm getting 404 error. How can I alter My code to pass multiple urls. Thanks in advance.
You just need to add a parameter in your rule
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+download\.php\?id=([0-9]+)&name=([^\s&]+)\s [NC]
RewriteRule ^ download/%1/%2? [R=301,L]
RewriteRule ^download/([0-9]+)/([^/]+)/?$ download.php?id=$1&name=$2 [L]