29

There are several reasons to remove extensions from URLs: To make the URLs look cleaner To make URLs easier to type To make URLs easier to remember To make URLs more SEO keyword friendly To be able to change technologies -- if you ever want to move your site from one technology to the other, its easiest to do so without users even knowing if there are no ...


13

I've been told that .htaccess should be avoided when possible, as it reduces the server performance and new servers disables it or just don't implement it anymore. The part about compatibility is absolutely not true; the part about performance is kinda true but probably irrelevant for you. What the person you quote was probably talking about is that it's ...


11

Yes, the latter one is better. Yet, if applicable, /john-smith is better than /johnsmith


10

Try this RewriteEngine On RewriteBase / RewriteRule ^edit/id/([0-9]+)/?$ edit.php?id=$1 [NC,QSA,L]


10

You shouldn't need to use percent encoding/hexcode in mod_rewrite parameters since mod_rewrite will encode special characters (?, #, , &, etc.) by default. To write a space in the rewrite pattern, use \s or just escape the space with a backslash (\). Whether space gets encoded as %20 or + depends on whether it's part of the query string or the URI. So ...


8

No offense intended, but Case Sensitivity is VITAL to urls today - they are used millions of times a day: bit.ly http://bit.ly/ri2LhQ http://bit.ly/ri2LHq Two vastly different sites - only possible because of case sensitivity


7

Thanks for your time to look at the question, but we appeared to have figured it out: Options -Multiviews -Indexes +FollowSymLinks RewriteEngine On RewriteBase / DirectorySlash Off # remove trailing slash RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L] # rewrite /dir/file?query to /dir/file.php?query RewriteRule ^([\w\/-]+)(\?.*)?$ $1.php$2 [L,T=application/x-...


7

All four of your URLs are different for SEO: http://www.example.com/product http://www.example.com/product/ http://www.example.com/product?source=googleps http://www.example.com/product/?source=googleps It doesn't matter which one of those four you use, but you have to pick one and use it consistently. Both slashes and parameters create new URLs to ...


6

The best way is to use 301 redirects in your .htaccess file, the 301 code signals to google that the url has been permanently redirected. I'd also recommend signing up for Google Webmaster Tools and submitting a sitemap to them, if you haven't already, as this will help them to understand the changes you're making to your site. redirect 301 /old-url http:/...


6

Compare these URLs: http://example.com/スター・ウォーズ×マンガ/ http://example.com/1234/ Which is going to bring in more relevant search traffic? It's possible that more people are searching for "1234" on Google than for the title of a Japanese Star Wars manga, but how likely are the "1234" searchers going to be interested in a thread about Japanese Star Wars mangas?...


6

All web servers have one or more "default files". It's the file that will be displayed whenever a visitor goes to a URL that ends in a slash /, i.e. a folder. If the default file name on your web server is index.php and a visitor goes to www.example.com/pagename/, they are actually accessing www.example.com/pagename/index.php. If there is no trailing /, ...


6

Just redirect by 301 HTTP status all your old URLs to the new ones. If you only change file extension, you can do it easily with an .htaccess file (if you use Apache as a web server). Put these lines in your .htaccess file: RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php Of course, change www.example.com by your domain name. By using 301 ...


5

Google sees the URL you publish. The rewrite happens in the background and is invisible to them. So as long as your URL is valid and the content you want can be reached with it Google will index it just fine.


5

Google explains the use and impact of URL parameters in this article: http://googlewebmastercentral.blogspot.com.au/2008/09/dynamic-urls-vs-static-urls.html The short answer is that with simple key/value query strings like yours, there's no issue.


5

Personally I am a fan of the one domain approach like you are doing but just thought I would also provide few more considerations to add to the already good advice given by others here. SEO is a major reason for going with two domains OR one. Two domains = two seperate marketable sites and one can be posted in app market places. On the other hand you're ...


5

There are several PHP microframeworks that allow you to create a simple application with "pretty URLs" by defining the available routes: Slim Flight Limonade Glue For example, this short Limonade app would respond to requests at the root domain (example.com/) and at the specified route (example.com/hello): <?php require_once 'vendors/limonade.php'; ...


5

Note that if you need to match against the query string, you need to compare against the QUERY_STRING server variable in a mod_rewrite RewriteCond directive. You can't match against the query string using a mod_alias Redirect (or RedirectMatch) or the RewriteRule (mod_rewrite) pattern - these all match against the URL-path only, which notably excludes the ...


5

You are using the ^ and $ (anchors in regex speak) because you are matching the whole URL, which is what most people want to do, so this is the most common example you see. If you omit the ^ and/or $ anchors then you are only going to be matching part of the URL. eg. anything$ is going to match "anything" at the end of the URL - this could match too many ...


5

It generally makes little difference. A 301 redirect may cause a short term drop in ranking, but nothing to worry about. An internal rewrite keeps the same URLs. You just need to be careful that you don't end up with duplicate content on multiple URLs.


4

If you want to redirect A to B, simply place the following directive in your .htaccess file: Redirect / http://example.com/home/ If you want to rewrite / as /name RewriteEngine On RewriteRule ^/$ /home/ [L]


4

Canonical URLs are to be used when two different URLs can be used to pull up the same content. If your URL rewriting causes this to happen then canonical URLs will be necessary. So if: www.mysite.com/london/kensington/apartments pulls up the same content as www.mysite.com/city=london&area=kensington&typeapartments then you need canonical URLs (...


4

Use canonical URLs or 301 redirects. Canonical URL: <link rel="canonical" href="http://www.domain.com/webdesign/" /> That will tell Google to use that URL in its search results.


4

IIS Server variables IIS server variables provide information about the server, the connection with the client, and the current request on the connection. IIS server variables are not the same as environment variables. http://msdn.microsoft.com/en-us/library/ms524602(v=vs.90).aspx


4

Aside from SEO, one issue is what the Url 'looks' like when people use/print/send it around. If you're going to redirect people to m when they go to www if they're on a mobile device, and redirect people to www from m when they're not, then what have you achieved by using separate domains? AFAIK, there are no benefits. But the reason people have decided to ...


4

If your exact search term is going to be the full 'John Smith', I am pretty certain that you are indeed correct and that having /johnsmith would be better as you are targeting a more refined search term and the extension matches up completely with the search term, which we can only assume is a good thing.


4

I finally found a solution. The second RewriteCond in my above code was unnecessary, and the first RewriteRule below, found at B&T's Tips & Scripts, adds a trailing slash if none exists (unless it's a file, like index.php). Here's my new .htaccess. Notice the trailing slash directive only needs to be applied once. .htaccess RewriteEngine On #ADD ...


4

This is the type of “cool” URI scheme that I aim for on my own personal website. Personally, the reason that I started to do so (and probably many more web designer/developers too!) was after reading the article “Cool URIs don't change” – this document was written by the World Wide Web's founding father, Tim Berners-Lee. In Tim Berners-Lee's famous article,...


4

The "hashbang" or "shebang" url syntax is an old hack designed to provide browser history to AJAX sites and to help Google index content that is loaded via JavaScript. See "What's the shebang/hashbang (#!) in Facebook and new Twitter URLs for?" for more. Your WordPress theme, "John Smith", is responsible for rewriting URLs in this way. It does this so that ...


4

The pseudo-code translation of your .htaccess file would be something along these lines: Line 1: In case we weren't previously planning to do anything special with URLs, we are now (RewriteEngine is an optional processing module and we're making sure its enabled). Line 2: When we're talking about rewrite URLs, from here on append the path / to the beginning ...


Only top voted, non community-wiki answers of a minimum length are eligible