0

I`m working on making a Simple URL Shortener But having some Issues with Mod_Rewrite ~

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^hu/([^/]*)$ /?code=$1 [L,QSA]
RewriteCond %{HTTP_HOST} !^AgeofW\.us$ 
RewriteRule ^(.*)([^hu/])$ http://%{HTTP_HOST}/hu/$1 [R=301]

The Idea of the URL is "AgeofW.us/hu/" to have a Trailing /hu/ at the end of the URL no matter what. But again. Im having some Issues with this. Ive tried for the last hour or two, and I have been forced to ask here! Anyone have a Idea? Or Explain to me? I`ll memorize it Lolz.

~~ This Generates a Infinite Loop that Generates: The requested URL /hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/ was not found on this server. ~ Over and Over again.

I`ve multiple Attempts, and Code Corrections, and have yet to comeup with a single Viable Solution.

Bioblaze Payne
  • 364
  • 3
  • 10
  • 1
    When you have problems with code, (1) post your code (✓), (2) have a clear description of what you expect the code to do (more or less here) and (3) tell us exactly what the current code is doing (totally missing). Please edit your question and edit in the missing information. – Sumurai8 Aug 17 '14 at 11:52
  • The Title Explains EXACTELY wht the issue is. The Description is there, Explaining the Issue as well. And the CODE itself is right there infront of you. Dont downvote a Question, cause your eye sight is bad. – Bioblaze Payne Aug 17 '14 at 12:16
  • Your problem description was "Im having some Issues with this". That is logical. You wouldn't post here if your code is doing what you expect it to do. It is not a good problem description though. A good problem description describes what you see on your screen, for example that you get an infinite loop. – Sumurai8 Aug 17 '14 at 12:25

1 Answers1

2

You can use:

RewriteEngine On

RewriteCond %{THE_REQUEST} !/hu/ [NC]
RewriteCond %{HTTP_HOST} AgeofW\.us$ [NC]
RewriteRule !^hu/ /hu%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^hu/([^/]*)/?$ /?code=$1 [L,QSA]
  1. In general keep redirect rules before rewrite ones.
  2. [^hu/] is not correct regex to match not hu/.
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • The requested URL /hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/ Is the Response of that. – Bioblaze Payne Aug 17 '14 at 11:50
  • `RewriteRule !^hu/` will not add `/hu/` if it is already there. Can you test this in a new browser. – anubhava Aug 17 '14 at 11:53
  • @BioblazePayne: Try it one more time with latest updates to the rules. – anubhava Aug 17 '14 at 12:10
  • @Sumurai8: Please elaborate why it would cause infinite loop. I will be happy to correct it. – anubhava Aug 17 '14 at 12:11
  • The requested URL /hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/hu/ was not found on this server. ~ Same issue. It creates a infinite loop. This is the exacte same issue i`ve been having. No idea why. I know the L Flag is for the Loop, but I cant figure out why it genertes the max /hu for the loop. – Bioblaze Payne Aug 17 '14 at 12:15
  • Its funny, several billion people on the Planet, I`m sure someone else is having the same Issue I am. But they simply dont post on here. ~ The Issue is not Fixed, I`ve updated the Code. That was posted, and it hasnt fixed anything. – Bioblaze Payne Aug 17 '14 at 12:26
  • This rule is not looping unless you have some code/rule removing `/hu/` from the URLs. Do you have more rules or is this the only code? – anubhava Aug 17 '14 at 12:27
  • Also make sure to test it in a new browser again. – anubhava Aug 17 '14 at 12:27
  • @BioblazePayne http://stackoverflow.com/questions/10156093/mod-rewrite-with-external-redirect-and-internal-rewrite http://stackoverflow.com/questions/12197749/mod-rewrite-error-310-too-many-redirects – Sumurai8 Aug 17 '14 at 12:43
  • Ok I`ve Opened it in a new Browser, and it works. ~ Updating the Post, with Information. And going to Mark it as Solved. Give me some Time. :) – Bioblaze Payne Aug 17 '14 at 12:55