Make friendly URL in php with .htaccess [duplicate] - .htaccess

This question already has answers here:
How to create friendly URL in php?
(8 answers)
Closed 1 year ago.
I am trying to implement SEO friendly URLs using .htaccess and PHP.
My URL is:
http://www.my_web_site.com/instructions.php?topic_id=6&category=NNNX&t=a-b-c
I want to this:
http://www.my_web_site/6/a-b-c
Can someone please help me make a following .htaccess content
Thanks.

You can use the following rule in your htaccess file to shorten your URLs
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.+)$ /instructions.php?topic_id=$1&category=NNNX&t=$2 [L]
With this rule , you can just type example.com/6/foobar instead of the full old URL path.

Related

change page.php?id=something-new-url-5dd669f4882a6 [duplicate]

This question already has answers here:
URL rewriting with PHP
(5 answers)
Closed 3 years ago.
i want to rewrite url from page.php?id=something-new-url-5dd669f4882a6 to domain.com/something-new-url-5dd669f4882a6
i have done some htaccess practices but it is not working.
here are my codes.
Options -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/page\.php\?id=(.*)\s [NC]
RewriteRule ^ /%1? [R=301,L]
my project is in directory like ,
www.example.com/demo/page.php?id=something-new-url-5dd669f4882a6
and i want to make it seo friendly
domain.com/demo/something-new-url-5dd669f4882a6
Look this: redirect in php
Page.php:
<php>
$tb=explode('=', $_GET);
if (isset($tb[1]) && $tb[0]=='id') header('Location: domain.com/demo/' . $tb[1]);
exit();
</php>

htaccess change from index.php?cat=123&page=456&title=789 to ?p=456? [duplicate]

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]

mod_rewrite not Working in grabkart.com [duplicate]

This question already has an answer here:
How to convert querystring to paths URL using mod_rewrite?
(1 answer)
Closed 8 years ago.
I Have My Own Website grabkart
Grabkart.com is online shopping portle
I want To make Change url of my website from
http://www.grabkart.com/productdetail.php?prodid=4385
to
http://www.grabkart.com/productdetail/4385
What Change I Have to make in my.htaccess file for this
RewriteEngine on
RewriteRule ^productdetail/([0-9]+)/?$ productdetail.php?prodid=$1
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Place the above in your .htacces, and assuming you have full admin rights on your server, and can access the hidden files - this should work.
In the above code the -d stands for Directory and -f for Regular File.
and the above will remove the .php extension from your URLs.
For example, if your page name is test.php in the main directory then you may access your page with the following urls:
grabkart/test
or
grabkart/test.php.
This will works in both conditions, and the same logic can be applied to anything you would like removing from the path.

WordPress like .htacces nice urls [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
.htacces to create friendly URLs. Help needed
I want to build a script like WordPress for the "nice urls", i copied the .htaccess rows and made some modifications, but on the side of the PHP i don't know how to build it.
I don't understand how it works.
With the help of Daniel A White i found the class in WordPress files.
WP_Rewrite: http://xref.wordpress.org/trunk/WordPress/Rewrite/WP_Rewrite.html
Start with setting rewrite engine and follow sym links
RewriteEngine On
# Drop the .php -- or any other extension you use.
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#Forces the site to switch to www.site.com - change the site/TDL below
RewriteCond %{HTTP_HOST} ^insuranceiwant\.com$
RewriteRule (.*) http://www.insuranceiwant.com/$1 [R=301,L]
Now name your pages something useful like site.com/contact-us
If you are pulling dynamic pages from a database, also add this:
Options +FollowSymLinks
Options +Indexes
RewriteRule ^([A-Za-z_]+)_([A-Z]+)/([A-Za-z0-9_-]+)$ /Resources/city.php?state=$1&region=$2&city=$3
That example shows that the dynamic page has a state name, state abbreviation, and a city pulling from the database and showing the page like so:
insuranceiwant.com/California_CA/Los_Angeles
For more information on regular expresion for your page names check out this useful site:
http://www.regular-expressions.info/

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]

Resources