3

I am getting some problem for without trailing slash url. I searched in Google, but not able to get the exact result.

  From Url : local.xxxx.com/stories

When I am trying with the above Url, It redirects to

  To Url : local.xxxx.com/sapp/View//stories/

Htaccess:

DirectorySlash Off
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -d
RewriteRule ^ /app/View/%{REQUEST_URI} [L]

Now I am getting 403 Forbidden error. You don't have permission to access /app/View//storieson this server.

If I will add trailing slash, then its working perfectly. If there is no slash, we can add slash at the end of the url if there are no params.

Can any body suggest how can I achieve this.

robert
  • 43
  • 7

1 Answers1

1

It is most likely due to the fact that /app/View/stories/ is a real directory and Apache's mod_dir is adding a trailing slash.

You can fix using this code:

DirectorySlash Off
RewriteEngine On

# internally add a trailing slash to directories
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -d
RewriteRule [^/]$ /app/View/%{REQUEST_URI}/ [L] 

RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -d
RewriteRule ^ /app/View/%{REQUEST_URI} [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • @Anuhava, Still url redirects to /app/View/stories/. Your assumption is perfect. but its not working for me. – robert Nov 26 '15 at 07:30
  • Question has been updated. We can Add slash at the end of the url if there are no params and .php extentions. Please check once – robert Nov 26 '15 at 09:26
  • What happens when you enter `http://domaon.com/app/View/stories` in browser? Does that also give 403? Try adding `Options +Indexes` at top of your .htaccess – anubhava Nov 26 '15 at 10:14
  • 1
    @anubava. I fixed this by using the below code. RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -d RewriteRule ^ /app/View/%{REQUEST_URI}/ [L] – robert Nov 26 '15 at 10:17
  • Ah that's right, glad it worked (answer updated with your working rule) – anubhava Nov 26 '15 at 11:03
  • Thanks Anubhava. Its working fine as per Url prospective. Getting another problem... In my all view pages, I am using Href links "./list.php" . Previously its working as expected. Now, It is taking from root path. Not taking from DocumentRoot/stories/list.php. So, I need to Append trailing Slash physically. any suggesstions? – robert Nov 27 '15 at 06:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/96322/discussion-between-robert-and-anubhava). – robert Nov 27 '15 at 06:56
  • Sorry I just came online. Is `list.php` located physically in `/app/View/` directory? – anubhava Nov 27 '15 at 15:36