0

I have a url, lets say its blog.art.ca/Customer/AAAABBBB/index.html and I want to hide Customer and AAAABBBB. Now AAAABBBB can be any 8 character alphanumeric code.

Options +FollowSymLinks -Multiviews -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^Customer/(.*)$ /$1 [L,R]
</IfModule>

I've tried numerous things, however, I either get ERR_TOO_MANY_REDIRECTS or it just causes the server to crash. Any suggestions would be much appreciated!

J-Americano
  • 188
  • 1
  • 10
  • "I want to hide Customer **and AAAABBBB**"? I don't see how the above code creates a redirect loop? And when you say "causes server to crash" - literally?! What error do you get? – MrWhite Aug 14 '15 at 19:57
  • Specifically it actually just says that the server has appeared to crash. I'm new to HostPapa so I'm not sure how else to clarify it. I'm not sure the above code does do a re-dircet as I've never had to deal with mod_rewrite and I couldn't find anything that explained how to handle for those changing codes and this was what I found for handling at least the Customer folder – J-Americano Aug 17 '15 at 12:09

1 Answers1

2

You still need to allow the requests to reach the actual requested resources, so you'll need two sets of rules, one to the browser, to show the new shorter URL (301 permanent redirect), and a second set to undo this mapping back to the original URL, so that Apache can find the right stuff to serve eg.

RewriteBase /

# Remove Customer/AAAABBB from the URL shown in the browser.
RewriteCond %{QUERY_STRING} !customer=
RewriteRule ^Customer/([^/]+)/(.*) /$2?customer=$1 [L,QSA,R=301]

# Internally undo any masked rewrites.
RewriteCond %{QUERY_STRING} customer=([^&]+)
RewriteRule (.*)  /Customer/%1/$1 [L]
arober11
  • 1,969
  • 18
  • 31
  • I attempted utilizing this as is and it returned a 500 (Internal Server Error) however it is rewriting the url. Normally the URL matchs custom.company.ca/Customer/AAAABBBB/index.html, where now the link becomes custom.company.ca/index.html?customer=AAAABBBB. – J-Americano Aug 17 '15 at 12:18
  • So the first rule is working as intended, the /Customer/Aaaaabbbb/ is no longer in the URL (hidden), but now passed as a CGI variable. Could be made a totally invisible Cookie with a simple tweak. Anyway the 500 error will be down to the implementation of the second rule creating a URL that does not match what your backend expects. – arober11 Aug 17 '15 at 12:31
  • I've attempted a numerous amount of changes to that second portion to get it to work and have run into an issue where it now seems to just be ignoring the .htaccess file. I do believe the answer you submitted to be correct I just can't reliably implement it apparently. – J-Americano Aug 17 '15 at 13:14
  • Remove / comment out the rules above, open a browser and surf to the site, and use the browser's Developer tools to capture the actual URL's requested for all the components. If the URL's don't map to physical assets on your web-server you have other rewrite rules you'll need to take into account. – arober11 Aug 17 '15 at 23:02
  • I was able to resolve my issue using `RewriteCond %{REQUEST_FILENAME} !-f` `RewriteCond %{REQUEST_FILENAME} !-d` `RewriteRule ^(.*)$ Employee/$1` As we decided to keep the other folder as a part of the URL. However I did get your code to function as intended so I've accepted it as the answer cause it was spot on. Turned out we had a rewrite rule on the entire domain. – J-Americano Aug 18 '15 at 14:48