how to create syntax for url rewriting - url

i have got this url like below :
http://www.mylink.com/property?id=34455
whats the rule to rewrite it to be in the following form without breaking
the css or anything. I see it done on multiple websites
http://www.mylink.com/property/3455
i already tried
RewriteRule ^property/?$ property.php [NC,L]

If the URL to be rewrited to http://www.mylink.com/property/3455 is http://www.mylink.com/property.php?id=34455 (notice the ".php" after property), the rule could be this one:
RewriteRule ^property/([0-9]+)$ property.php?id=$1
You can test your rules here http://martinmelin.se/rewrite-rule-tester/

Related

.htacces how to write htacces rewrite rule for seo friendly url

I'm just new to .htacces
I want:
example.com/page.php?page=how-to-learn
changed to:
example.com/how-to-learn
I google'd some and tried but no change url.
That's not how .htaccess work : it won't change your links to display the corrected version, but it looks for a match in the expressions you'll write into it to rewrite the correct parameters.
For example, in your code, your .htaccess sould look something like this :
RewriteEngine On
RewriteRule ^([a-z-]+)$ page.php?page=$1 [QSA,L]
If you write example.com/how-to-learn in your browser, you'll be able to see the content of example.com/page.php?page=how-to-learn.
I advise you to be VERY careful though : as the expression is VERY permissive, you'll have to check in the page.php file that the file if legitimately allowed to be loaded.

don't display .php extension in address bar(php)

First of all this method clearly working on github, for example pages showing done:
https://github.com/account
https://github.com/inbox
There is no .php extension at all + not needed ?page=account or ?page=inbox
In my opinion it's done via .htaccess.
Maybe someone knows how it should look in order to archieve same effect like github site ?
This can be achieved using mod_rewrite for apache
You put a .htaccess file in your document root and give it rules (Regular Expressions) to match the called URLs with
It looks similar to this:
RewriteEngine On
# rule to call MyPage.php if you call the URL http://yourdomain.com/MyPage
RewriteRule ^(.*)$ $1.php
# rule to add GET params
RewriteRule ^(.*)$ index.php?page=$1
There are several tutorials regarding mod_rewrite on the internet

A little bit help in url rewriting, please!

I have a short question about url rewriting...
I have a website. Let's say http://www.example.com/
with some subsites:
http://www.example.com/a.php
http://www.example.com/b.php
etc...
and some "special" urls like
http://www.example.com/c.php?i=1#link1
http://www.example.com/c.php?i=1#link2
http://www.example.com/c.php?i=2#link1
Now I would like to write a .htaccess file to convert current urls into rewritten urls like
http://www.example.com/a/
http://www.example.com/c/1/#link1
I'm not an expert in url rewriting, so could somebody please help me?
Best reagards.
RewriteRule ^a$ a.php [L]
RewriteRule ^c/(.*)/(.*) c.php?i=$1$2
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^a.php a/
RewriteRule ^b.php b/
Should work as far as your static pages go, you can not rewrite the hash because the hash is not sent to the server (as discussed here). If you need to rewrite the hash I would suggest changing the hash to another GET variable (eg u), in that case just add this to your htaccess: RewriteRule ^c.php?i=(.*)&u=(.*) c/$1/$2. If you simply intend to leave the anchor though, you can omit it from your rewrite and everything should be fine (...becuase the server never sees the hash/pound symbol), and in that case you should add this to your code RewriteRule ^c.php?i=(.*) c/$1/.

Htaccess RewriteRule trouble - How to redirect to a "re-written" url on the server?

I have the following rewrite rule which is working fine:
RewriteRule ^([a-zA-Z\-]+)[/]?$ apply/?survey_folder=$1
which turns this: address.com/folder1/
into this: address.com/apply/?survey_folder=folder1
The problem is that I can't figure out a way to use a redirect to the rewritten URL. Using cfml as an example, (cflocation url="http://www.address.com/folder1/") throws an error because, of course, the folder "folder1" doesn't actually exist on the server.
I can get the user redirected to the correct page by using /apply/?survey_folder=folder1, but that defeats the purpose of having the rewrite rule at all.
Is there any way to redirect to a URL rewritten by htaccess? I'm new at RewriteRule.
Add the [L] flag to the rule otherwise you're in danger of infinite loops and other problems.
The redirect you need is incredibly simple.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /apply/(index\.php)?\?survey_folder=([\ ]+)\ HTTP/
RewriteRule ^apply/(index\.php)? http://www.example.com/%1 [R=301,L]
RewriteRule ^([A-Z-]+)$ /apply/?survey_folder=$1 [NC,L]
Do not let both URLs with trailing slash and URLs without trailing slash resolve to the same content. The URL for a page does not have a trailing slash. Add another preceding redirect to strip trailing slashes in that case.
Have you tried setting RewriteBase? Its purpose is to map the URL to the physical location on the server. I'm not completely sure this is the problem you are having, but it does sound like a possibility.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritebase

MVC url Rewriting something like http://controller.website.com

Using MVC. Is there a way to make any url like .example.com to point to example.com/user/
as in http://marwan.example.com to point to example.com/user/marwan
The controller is user and the action is index which takes marwan as its variable.
One idea I had is to make a custom error page to handle 404 and see if the url starts with something like *.example.com and redirect to the proper controller. There must be a better way to do this!
Take a look at this answer it may help you out.
ASP.NET URL Rewriting
You can try the following:
RewriteConf %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/user/%1$1
RewriteRule ^/user/([a-zA-Z0-9]+)\.example\.com/(.*) http://example.com/user/$1/$2 [NC,L]
What this rule does is first insert the host into the URL path and then strip out the correct values from the host and write it the way you want on the backend.

Resources