URL重写规则在php中不起作用

i am using godaddy hosting and addon domain. i want to make my long url to short url.

for example my url is follwing: www.example.com/events/landing_event.php?url=text-first

and i want following url: www.example.com/events/text-first

for this i am using following rewrite url in .htaccess file

RewriteRule ^([a-zA-Z0-9-/]+)$ events/landing_event.php?url=$1 [L]

RewriteRule ^([a-zA-Z0-9-/]+)/$ events/landing_event.php?url=$1 [L]

but this rewrite rule is not working. so please help how can i make short url.

Use this source after you make sure RewriteEngine Enabled and On

RewriteEngine On
RewriteRule ^events/([^/]*)$ /events/landing_event.php?url=$1 [L]

The original URL: http://www.example.com/events/landing_event.php?url=text-first

The rewritten URL: http://www.example.com/events/text-first

Updated with 500 Internal Server Error

Your code is guaranteed to generate 500 internal server error because it is causing infinite looping. Reason is that your matching URI pattern is: ^events/([^/]*)$

Which matches your URLs before and after rewrites. And once it reaches max allowed internal rewrite limit Apache throws 500 internal server error and bails out.

Change your code to this

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]*)$ /events/landing_event.php?url=$1 [L,QSA,NC]

Try this code :

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /events/landing_event.php?url=$1 [L]

Add this in your .htaccess file

You can see there are many ways to achieve that goal.

Also

RewriteEngine On
RewriteRule ^events/([^/]*)\.html$ /events/landing_event.php?url=$1 [L]

would do the job. So basicly, how does the full scope of your project urls look like?

Like do you always want to print the parameters? If yes, also the name sometimes or also the value?