2

Trying to get www.example.com/test.php?archives=testing to www.example.com/archives/testing

According to godaddy they have mod_rewrite enabled by default

Here is my .htaccess file:

rewriteengine on
rewritecond %{HTTP_HOST} ^example.com$
rewriterule ^example\/(.*)$ "http\:\/\/www\.example\.com\/$1" [R=301]
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^archives/(\w+)$ test.php?archives=$1 [L]

However this is not working, when i go to www.example.com/archives/test I get a 404, suggestions

kqlambert
  • 2,693
  • 6
  • 33
  • 50
  • What is a case where its not working? chances are its your regex the `([a-z]+)$` thats not working out for you. I believe you will also need a couple conditions to trigger the rule as well. – chris Aug 03 '12 at 21:19
  • It must work, even without `Options` line. See `access` & `rewrite` logs. Mod_rewrite doesn't work properly. – Alexander Palamarchuk Aug 03 '12 at 21:19
  • I hosted a website on godaddy before, had some issues with url rewrite as well, but it's working fine right now, in my htaccess file, I don't have `Options +FollowSymLinks -MultiViews` and `RewriteBase /`, maybe give a shot? – lusketeer Aug 03 '12 at 21:20
  • @chris could you give a link on how to trigger the rewrite – kqlambert Aug 03 '12 at 21:25
  • This is an answer I gave someone a while back for short url rendering. It in concept is what your attempting to do, but will have to be altered some to work for your specific need.. http://stackoverflow.com/questions/11022509/php-dynamic-db-page-rewrite-url/11022705#11022705 – chris Aug 03 '12 at 21:37
  • Did you try with the right Upper/lowercase for the first 3 lines? – C.A. Vuyk Aug 04 '12 at 06:02

4 Answers4

2

I just left this in a comment but i might as well put it here so its seen easier. I wrote an answer for someone thats helped others out over time, and in the end this isn't exactly an answer to what your asking however its more of a stepping stone in the direction. The original question was asked how to work with short url strings and make them work in a fashion like your looking for, but rather copy and paste that answer here. Ill let you go there and read over it.

Its not to go without saying you will need to alter the rule a little for your specific needs but it will in the end serve its purpose for getting you where you want to be.

PHP dynamic DB page rewrite URL

Community
  • 1
  • 1
chris
  • 36,115
  • 52
  • 143
  • 252
1

You need some rewrite conditions to specify when this rule will be used. Without them, you will keep running the same rewrite rule indefinitely, giving you an error. Try:

RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^archives/(\w+)$ test.php?archives=$1 [L]
the_red_baron
  • 868
  • 7
  • 14
  • Rewritecond should be on separate lines, I'm using a phone so formatting is off. – the_red_baron Aug 03 '12 at 21:26
  • The [L] flag, which tells mod rewrite that this is the last rule to be applied, should be on the same line as the rewrite rule with a space before it. – the_red_baron Aug 03 '12 at 21:30
  • Thanks Tried it but no luck when going to example.com/test.php?archives=test, url stays the same. – kqlambert Aug 03 '12 at 21:31
  • Mod_rewrite works for urls that don't exist, so you should actually be directing traffic to example.com/archives/test. Mod rewrite then silently rewrites the URL to an actual existing file and displays that one instead of the nonexistent one. – the_red_baron Aug 03 '12 at 21:33
  • Well im getting a 404 when trying to go to example.com/archives/test – kqlambert Aug 03 '12 at 21:37
  • See revised code. Also, make sure your htaccess is in your root folder – the_red_baron Aug 03 '12 at 21:41
  • htaccess file is in root, updated question to show complete .htaccess file however still getting the 404 – kqlambert Aug 03 '12 at 21:49
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/14878/discussion-between-kricket-and-the-red-baron) – kqlambert Aug 03 '12 at 21:50
  • Wish I could, I'm on the go and need to run. If I find time later I'll help, buy cant guarantee it. Look for basic tutorials for "pretty urls". Good luck! – the_red_baron Aug 03 '12 at 21:51
0

How about this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^archives/(.+)$ /test.php?archives=$1 [L]
</IfModule>
Xhezairi
  • 544
  • 6
  • 17
0

Without is being super clear what you are trying to get from your rewrites I suggest:

Options -MultiViews
ErrorDocument 404 default
RewriteBase /
Mike_GoDaddy
  • 1,121
  • 1
  • 7
  • 9