Jump to content

Shortening URLs


bravo14

Recommended Posts

Hi Guys

 

I am new to .htaccess and I am trying to shorten the URL from something like

 

http://79.170.44.125/platinumbrides.co.uk/page.php?page_id=about_us

 

to

 

http://79.170.44.125/platinumbrides.co.uk/about_us

 

Looking through tutorials out there I have the htaccess as

 

RewriteEngine On

 

RewriteRule ^([a-zA-Z0-9_-]+)$ page.php?page_id=$1

RewriteRule ^([a-zA-Z0-9_-]+)/$ page.php?page_id=$1

 

However this is not working it still shows the original url and if I type inthe shortened URL I get an error saying the page cannot be displayed

 

What am I doing wrong? :confused:

 

 

Link to comment
https://forums.phpfreaks.com/topic/192484-shortening-urls/
Share on other sites

I always find that when debugging, adding the [R] flag to the end of rules can help you see why it isn't working. You don't appear to be specifying a RewriteBase, as such you should probably change your pattern to...

 

RewriteRule ^([a-zA-Z0-9_-]+)/?$ /page.php?page_id=$1

 

The key difference is the forward slash before the second URI. Note I also combined the two RewriteRules by simply saying the trailing slash is optional.

Link to comment
https://forums.phpfreaks.com/topic/192484-shortening-urls/#findComment-1014253
Share on other sites

Looking at your original code it would appear that the IP is your domain meaning platinumbrides.co.uk is a folder on the domain. Which means you need to change the relative paths of your domains, in that case you're probably going to need something more like...

 

RewriteRule ^platinumbrides\.co\.uk/([a-zA-Z0-9_-]+)/?$ /platinumbrides.co.uk/page.php?page_id=$1

Link to comment
https://forums.phpfreaks.com/topic/192484-shortening-urls/#findComment-1014277
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.