I have created a text link on my Website.
when a user click on the link, it takes him to a the page: www.example.com/toronto_streets.php
but, I want the URL to be displayed as www.example.com/toronto.on/
then when user selects one street from this page, the url will be www.example.com/street_landing_page.php?street=Option
but, I want the URL to be displayed as www.example.com/toronto.on/house-for-sale-option
I tried with editing .htacccess file but that didnt work...
Here is what I added to the .htaccess file:
RewriteEngine on
RewriteRule ^toronto.on/house-for-sale-condo-mls/?$ house-for-sale-condo-mls.php [NC] #...
So will the above line Redirect www.example.com/toronto.on/house-for-sale-condo-mls/
to www.example.com/house-for-sale-condo-mls.php
?
when Im calling the URL, www.example.com/toronto.on/house-for-sale-condo-mls/
, Im getting this error :
The requested URL /toronto.on/house-for-sale-condo-mls was not found on this server.
Update:
This is my current .htaccess file. It Redirects www.example.com/toronto.on
to a page called cate.php
with the city value= 'toronto' and province='on'.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ example.com/$1 [R=permanent,L]
In the .htaccess, you would use a set of rewrite rules, such as the following:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^toronto.on(/*)$ /toronto_streets.php [L]
RewriteRule ^toronto.on/house-for-sale-option /street_landing_page.php?street=option [L]
You can use this site to help you test the rewrite rules: click here
However, as others have pointed out, what appears in the URL bar will be what a href that is requested by the page. Thus the links on the page html should be modified to user the friendly URLs (eg /toronto.on/house-for-sale-option, rather than the backend url /street_landing_page.php?street=option
1) There are 2 mistakes in the Rewrite Rule you stated in your Question:
RewriteEngine on
RewriteRule ^/house-for-sale-condo-mls.php?$ /toronto/house-for-sale-condo-mls/ [QSA,NC,L]
One is in your head: **You need to have your "friendly" urls embedded in any html you sent to the client. ** The .htaccess doesn't make bad to pretty URLS it makes pretty URLS internaly redirecting to the real site. That means that your Links on the site need to contain:
<a href="/house-for-sale-condo-mls.php">The Text</a>
The seccond one was a missing Backslash.
The same for Point 1 of your Question:
RewriteRule ^/toronto.on /toronto_streets.php [QSA,NC,L]
Ist probably a good Idea to put another Rewrite Rule like this in front of the Top ones:
RewriteRule ^/toronto_streets.php /toronto.on [R=301,L]
If somethere the Link isn't Change (an external ressource) it Redirects the user to the pretty URL.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.