clean URL using php or .htaccess [duplicate] - .htaccess

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

Related

How to redirect /?page=1 to /page/1 using htccess [duplicate]

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.

htaccess - How can I redirect all ".php" pages to "/" pages? [duplicate]

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.

How to create pretty url using htaccess [duplicate]

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]

How do I get a url to use pretty urls? [duplicate]

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]

.htaccess redirect [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
.htaccess redirect
How exactly, with a .htaccess file i'm presuming, would i redirect people from this URL: http://blog.twostepmedia.co.uk/win-traffic-with-charlie-sheen-and-the-yahoo-boss-api/ to something like http://www.twostepmedia.co.uk/blog/win-traffic-with-charlie-sheen-and-the-yahoo-boss-api/
Thanks :)
You're better off using a rewrite rule in your .htaccess of the blog.twostepmedia.co.uk domain.
Something like
RewriteEngine on
RewriteOptions MaxRedirects=10 # this will just stop and bugs in the code causing a infinite loop
RewriteRule ^(.+)$ http://www.twostopmedia.co.uk/blog/$1 [R=301,NC]
The rewrite rule grabs whatever follows 'blog.twostepmedia.co.uk/' and rewrites to the new url. The [R=301,NC] sets this to be a permanent redirect, which means you won't get penalised from duplicate content by search engine spiders.
Hope that helps :)

Resources