How can I create a dual URL system?

How can I create a dual URL system? - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, mod-rewrite, , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I'm looking for a simple trick



Let's say I have a Wordpress installation and image resources in this URL



http://example.com/wp-content/images/example.jpg


I would like to have the possibility of having another accessible URL (not rewritten) that points the same resources with a different route. For example



http://example.com/content/images/example.jpg


I don't need any changes in the Wordpress platform per se. Only being able to link this alternate URL without a redirect of any kind.



As the title suggests, being able to have dual URLs for the same resources.



I've tried some ideas with .htaccess but could never manage to make this work., so I'm not 100% if that is the way to go, or if there are better alternatives like Apache Virtualhosts or something.


Solution :


better alternatives like Apache Virtualhosts or something.




If you have access to the server-config, then you can use the Alias directive in the vHost to route all requests for /content/images to /wp-content/images.



For example:



Alias "/content/images/" "/wp-content/images"


Now, a request for /content/images/example.jpg would be sent to /wp-content/images/example.jpg.



However, if you are limited to using .htaccess then you will need to rewrite the URL using mod_rewrite.



Found the solution through .htaccess
Never sure if it's the best, but it works:



RewriteRule ^([_0-9a-zA-Z-]+/)?content/(.*) /wp-content/$2 [QSA,L]

Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect