0

I have installed Yourls in my domain under a subdirectory The service works on its place. A working url is http://mydomain.com/1/abc where 1 is the subdirectory.

Is there a way to make a rule to be able to call http://mydomain.com/1abc to resolve to the working url http://mydomain.com/1/abc ?

I don´t quite understand where to put it and how to setup the rule, since I am not sending parameters.

Thanks

1
  • does the abc change? Is that supposed to be unique also are there any other rules that come with yourls? Commented Feb 19, 2014 at 14:41

1 Answer 1

1

Assuming the subdirectory always consists of numbers, and the subdirectory is a physical directory, make a file .htaccess in your www-root and add the following to it:

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^/([0-9]+)[^/]*$ RewriteCond %{DOCUMENT_ROOT}/%1 -d RewriteRule ^([0-9]+)([^/]*)$ /$1/$2 [L] 

It first checks if the url matches ^([0-9]+)([^/]*)$ (starts with 1 or more numbers, and contains any non-slash character after that. The RewriteCond %{REQUEST_URI} ^/([0-9]+)[^/]*$ matches the same thing, because we need the supposed directory-part in the next condition. RewriteCond %{DOCUMENT_ROOT}/%1 -d checks if the number we think is a subdirectory, is actually a directory. If that is the case, the url will be internally rewritten to /number/restoftheurl.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.