SEO Friendly URLs & .htaccess - .htaccess

I'm trying to make my URLs SEO friendly but am having issues with my .htaccess
This is how my URL currently looks:
http://www.mysite.com/dns/?domain=stackoverflow.com&submit=Report
But I want it to show like this:
http://www.mysite.com/dns/stackoverflow.com
I've tried so many things I don't know if it's even possible to do so I just wanted to start over with guidance from you guys. The .htaccess I'm working with is in the /dns/ folder. Any help would be greatly appreciated.

Step 1: change all of your links and anchors in all of your pages to look like this: http://www.mysite.com/dns/stackoverflow.com, so when someone clicks a link on your site, they go to a link that looks like http://www.mysite.com/dns/stackoverflow.com instead of http://www.mysite.com/dns/?domain=stackoverflow.com&submit=Report
Step 2: In the htaccess file in your document root, add these rules (above any rules that you may already have):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?dns/(.+)$ /dns/?domain=$1&submit=Report [L,QSA]
Step 3: In the event that a GET method form submission is generating the link, you can add these rules too:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /dns/\?domain=([^&\ ]+)(&submit=Report)?
RewriteRule ^/?dns/?$ /dns/%2? [L,R=301]

See post url rewritin using .HTACCESS
www.mysite.com/dns/?domain=stackoverflow.com&submit=Report
to
www.mysite.com/dns/stackoverflow.com/Report
Try this
Options +FollowSymLinks
RewriteEngine On
RewriteRule \.(js|css|jpe?g|png|gif)$ - [L]
RewriteRule "^dns/([ \w-]+)/([ \w-]+)/?$" dns/?domain=$1&submit=$2 [L,QSA]

Related

htaccess - the second url param is not visible

example.com/play/music to example.com/play.php?c=music
here is my code which works:
RewriteRule ^play\/music$ play.php?c=music [L]
now I have an extra url param (id as integer) added:
example.com/play/music/54
need to be - example.com/play.php?c=music&id=54
here is my beginning try:
RewriteRule ^play\/music/\d+/?$ play.php?c=music&id=$1 [L]
the page is there but problem is with id param - php doesn't see it
could someone help and explain ?
also, maybe is possible to join both rules (with and without id) in one ?
With your shown samples, please try following .htaccess rules file. Make sure to clear your browser cache before testing your URLs and make sure your .php files(eg: play.php etc) are residing along with .htaccess rules file.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ $1.php?c=$2&id=$3 [QSA,L]

How to rewrite url for certain pages in htaccess?

I am trying to show different url and redirect users to specific url with .htcaccess when they click on a blog post but to no avail.
Lets say the url is: http://localhost/mySite/article.php?article_title=test-title
then I would like to show it as http://localhost/mySite/article/test-title
This is my current htcaccess file:
#turn on url rewriting
RewriteEngine on
#remove the need for .php extention
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
#rewrite rule for blog
RewriteRule article/([A-Za-z0-9-]+) /mySite/article.php?article_title=$1
But for some reason it is not redirecting/showing the correct url. I am not getting any errors.
EDIT
Trying to ask my question again and explain it better. Let's say the url is
http://localhost/www.example.com/admin/editUser.php?user_id=126
and I would like to rewrite the url like this:
http://localhost/www.example.com/admin/user/126
then how can I achieve this. I tried using this website to check the modified url but it does not work. Seems like it does not work with any of the accepted answers here in stack at all.
This is my htaccess file atm. It is in the root of www.example.com
#turn on url rewriting
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^user/([0-9]+)/?$ /editUser.php?user_id=$1 [NC,L] # Handle user edit requests
Apache Module mod_rewrite is enabled. Also added an alias. Still no changes in the url. If I try something really basic like this:
# redirect to .php-less link if requested directly
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.+)\.php $1 [R=301,L]
it works fine.
Why is the users redirect not working? What am I doing wrong.
Try it like this for your rule for article url in mysite directory.
RewriteRule ^article/([A-Za-z0-9-]+)$ article.php?article_title=$1 [QSA,NC,L]
you need to mention start ^ and end $ of string.

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/

Got stuck in a very basic .htaccess rewrite

<h1>' . $name. '</h1>
The above is the reference which points to my profile1.php file. This file is called index.php . It currently displays the urls as this:
http://www.domain.com/interact/profile1.php?id=36
I have tried implementing the .htaccess file to rewrite the url. I tried many combinations and most of them gave a 500 error and some did not rewrite the url.
This is the .htaccess file which I use, it does not make the url to change.
I want the url to look like http://www.domain.com/interact/profile/36
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ profile1.php/$1 [QSA,L]
</IfModule>
I know this is a very basic question but I seem to stuck in it and have read basic tutorials but am not able to implement it properly.
The files index.php ,profile1.php and .htaccess are in folder named interact.
Tell me any changes required in php or .htaccess files.
It currently displays the urls as this: http://www.domain.com/interact/profile1.php?id=36
...
I want the url to look like http://www.domain.com/interact/profile/36
Step 1:
Change your content to have links like this:
<h1>' . $name. '</h1>
This way, when you click on a link the URL that will appear in the URL address bar is will look like: http://www.domain.com/interact/profile/36
Step 2:
Then you need to use these rules to internally change it back:
RewriteEngine On
RewriteBase /interact/
RewriteRule ^profile/([0-9]*) profile1.php?id=$1 [L,QSA]
In order to point any external links, like google index bots to the new URLs, you'll need to add these as well:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /interact/profile1\.php\?id=([0-9]*)
RewriteRule ^ http://www.domain.com/interact/profile/%2 [L,R=301]
try this
RewriteRule ^interact/profile1.php/(.*)$ interact/profile1.php?id=$1 [L]
i don't know what make QSA modifiers does so i remove it. If you know what, use it)

.htaccess 2 Dyanamic Rewrite URL

I have a dynamic url at
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%|tag|&limit=20
where the '|tag|' and '20' part change depending on the tag. This is Movable Type blogging platform which is written in perl. The '|tag|' part is a place holder for the tag. For example, if the tag was 'there' the url would be
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%there&limit=20
and not
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%|tag|&limit=20
I was wondering how to rewrite that in htaccess because everything I try doesn't work. I want it to be
http://www.technicae.net/tag/|tag|
instead of
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%|tag|&limit=20
can you please help me?
note
The URLS are not functional.
This is what you're searching for :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^tag/([^/]+)$ cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%$1 [L]
RewriteRule ^tag/([^/]+)/limit/([^/]+)$ cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%$1&limit=$2 [L]
This will allow thos kind of url :
www.domain.com/tag/<myTag>
www.domain.com/tag/<myTag>/limit/<myLimit>
But not :
www.domain.com/limit/<myLimit>
Assuming you are using Apache, make sure you have mod_rewrite enabled.
The .htaccess you should use (this may need tweaked) is:
RewriteEngine On
RewriteRule ^tag/([^\.]+)$ cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%$1&limit=20 [NC,L]

Resources