Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule drives me crazy

RewriteRule

         

ScubaMaster

3:58 pm on Apr 1, 2011 (gmt 0)

10+ Year Member



I am probably not the first jumped out of the window after working with RewriteRules.

I like to rewrite
[abc.com...]
into
[abc.com...]

What I've got is
RewriteEngine On
RewriteRule ^.*/my\-site/$ [abc.com...] [R=301,NC,L]

The result is
[abc.com...]

Tried my regexpr in an online tester and that works.

Why is this not working?

g1smd

12:40 am on Apr 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You asked for a rewrite and then presented code for a redirect.

Which one of those two things do you want?

Explain in more detail what has happened to the file inside the server. Has it been moved to a new location inside the server, or to a different server?

Explain in more detail what you want in terms of URLs. Do you want users using the old URL to now be forced to use a new URL? Or would you prefer that users continue to use the old URL to access the content?

What URL was shown in the href part of the links on the pages of your site? What URL is shown now, the same as before or a different/new one?

Answer all parts in detail.

Use example.com to stop the forum autolinking the URLs

ScubaMaster

1:13 am on Apr 2, 2011 (gmt 0)

10+ Year Member



The rules are called RewriteRule.

The case is that the file /my-site/index.php is moved permanentely to /other-site/my-new-site.html on the same server. In case external links are still using the old url i like to tell the agent it has been moved permanentely [R=301].

Thanks

ScubaMaster

1:15 am on Apr 2, 2011 (gmt 0)

10+ Year Member



p.s.

the uri in the http-request can be /my-site/ or /my-site/index.php

wilderness

2:06 am on Apr 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule [httpd.apache.org] is a syntax in the Apache module mod_rewrite, however how you apply the expression determines whether it's used as a "redirect or a rewrite" (neither are defined the same as "RewriteRule")

ScubaMaster

5:34 pm on Apr 2, 2011 (gmt 0)

10+ Year Member



Thanks everybody,

Complicated stuff! I use mod_alias and php now for the redirects. Thanks to you I know a bit more about the difference in both modules.

Still strugling with RewriteRule though.

g1smd

6:02 pm on Apr 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Mod_rewrite is used to connect a URL request to a file.

With a redirect you assign a new URL to the new file and use a new URL to access it and tell all agents asking for the old URL to use the new URL.

With a rewrite, you move the file to a new location inside the server, and continue to use the old URL to access that new file. The rewrite connects the URL request to the file.