Reputation: 5099
So, I need to set custom URLs so that
goes to:
http://example.com/dynamic.php
I know this is a pretty simple operation but after some googling, I can't find the answer. What is the simplest method for handling something like this?
Upvotes: 2
Views: 6205
Reputation: 20431
The regular expression for that would be something like this:
RewriteEngine on
RewriteRule ([^/]+)/?$ $1.php [L]
Running the regex on the left will return "dynamic/" or "dynamic" if the forward slash is not included. Then it will replace what was captured in the first parenthesized block ("dynamic/") with dynamic.php.
You can try your URL rewrites here:
And your general regex here:
Upvotes: 4
Reputation: 6220
There's several methods of achieving this:-
RewriteEngine on RewriteRule ^$ dynamic.php
<script type="text/javascript"> window.location = "http://example.com/dynamic.php" </script> <script type="text/javascript"> location.href='http://example.com/dynamic.php'; </script> <script type="text/javascript"> location.replace('http://example.com/dynamic.php'); </script>
However, if using PHP instead (recommended), include the following:-
header("Location: http://example.com/dynamic.php");
Remember to use ob_start(), ob_end_flush() to fix the output buffer, if you get the error that the headers are already sent and you can't modify the header information.
Hope this helps.
Upvotes: 1
Reputation: 11500
you have to do it using url rewriting. that depends on the web server that you are using . for example, you can use .htaccess if your webserver is Apache. Apache URL Rewriting.
Upvotes: 6