This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 6 years ago.
I have a link like http://example.com/file.php?id=7gJKw2&d=78sfmnnsd8
I want to make this above url as
http://example.com/file/7gJKw2/78sfmnnsd8
Here is what I've tried
RewriteRule ^file/([a-zA-Z0-9_.-]+)$ file.php?id=$1
RewriteRule ^file/([a-zA-Z0-9_.-]+)/$ file.php?id=$1
How can i add the value of d & make it good looking?
You can bundle the entire a-zA-Z0-9_ pattern into a simple \w. As to the real question, just add the second part as follows:
RewriteRule ^file/([\w.-]+)/([\w.-]+)/?$ file.php?id=$1&d=$2 [L]
RewriteRule ^file/([\w.-]+)/?$ file.php?id=$1 [L]
Related
This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 3 years ago.
I want to Redirect http://www.example.com/?page=1 to http://www.example.com/page/1 using Htaccess.
copy & paste this code in .htaccess file in your root directory
To keep the prefix and replace the last part with a query string
RewriteCond %{QUERY_STRING} !^id=
RewriteRule ^root/pages/(.+)$ /root/pages/?id=$1 [L]
The RewriteCond is needed to prevent a rewrite loop.
This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 4 years ago.
HOw to make this url:
http://localhost/TrustyWrenchVersionOOP/?page=home
to this url:
http://localhost/TrustyWrenchVersionOOP/home
Rewrite your .htaccess rules like so. This is what I use and it works fine. There's different ways to achieve this, a quick google search probably would've yielded quicker results though
RewriteEngine on
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1
This question already has answers here:
Remove .php extension with .htaccess
(17 answers)
Closed 4 years ago.
My URLs look like this:
mywebsite.com/subpage-name.php
I want my new links to look like this:
mywebsite.com/subpage-name/
How can I redirect all my ".php" pages to "/" pages?
You have to add a RewriteRule in your .htaccess with a regex.
RewriteRule ^(.*)$ http://www.thenewdomain.com/$1 [R=permanent,L]
Make sure to add
RewriteEngine on
Before applying the redirect rule.
Happy Coding.
This question already has answers here:
Rewriting URL with selected query string parameters in .htaccess
(3 answers)
Closed 8 years ago.
How do change:
domain.nl/index.php?cat=123&page=456&title=789
to
domain.nl/?p=456
I think I need to change .htaccess and use rewrite rules, but I can't get it to work.
I would like to use the value in variable page in the new URL. Thanks!
This is only possible if index.php doesn't need the information in the cat and title variables, since you remove this information from the url. I am also assuming that index.php uses the query variable, and not the THE_REQUEST variable to get this information. You need two rules. One to externally redirect the old url to the new url. The other one needs to only work on external requests that match the url, and internally rewrites it to the old url that works.
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /\?p=([^&]+)
RewriteRule ^ /index.php?page=%1 [L]
RewriteCond %{QUERY_STRING} page=([^&]+)
RewriteRule ^index\.php$ /?p=%1 [R,L]
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Url Rewriting Help
How do I get a url ending in /index.php?p=2 to display as /2 instead using .htaccess (pretty urls)?
I currently am working on a webcomic displaying site but I have run into a problem with my .htaccess file. I am trying to rewrite /index.php?p=2 to /2 but for some reason it is not working.
So yeah any help would be much appreciated!
.htaccess can't rewrite /index.php?p=2 into /2. You are approaching the problem in reverse.
Rewrite rules tells Apache to do something when fetching a specific URI. What you really need to do is tell Apache to "rewrite" a request to /2 so that it fetches /index.php?p=2 instead. You can do so with the following RewriteRule:
RewriteRule ^([0-9]+)$ index.php?p=$1 [L]
and then change, in your HTML, every single link to point to the rewritten URI instead of the canonical one. Apache will not "rewrite" your links for you. It will however, with the help of the rule above, fetch the proper resources when the client queries for /2.
Make an .htaccess file similar to this one... (the flags may need to be modified/varied per mod rewrite flag documentation: http://httpd.apache.org/docs/2.3/rewrite/flags.html)
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z_0-9-]+)/?$ index.php?p=$1 [QSA,L]