Reputation: 16615
I'm trying to use pretty URLs on my site, and I don't know too much about htaccess, but after some search I ended up with this:
RewriteEngine On
RewriteRule ^([a-z]+)\/([0-9]+)\/?$ content.php?action=$1&id=$2 [NC]
I'm trying to change this:
mysite.com/cms/content.php?action=content&id=80
into:
mysite.com/cms/content/80
But somehow it's not working and what I get is a blank screen and a 404 error,
Failed to load resource: the server responded with a status of 404 (Not Found) --in-- /cms/files/plugin/tinymce/tinymce.min.js
About the 404 error: It should load a .js file from mystie.com/files/plugin/tinymce/tinymce.min.js -- not -- mystie.com/cms/files/plugin/tinymce/tinymce.min.js
My htaccess file is in the root folder. Am I doing something wrong?
I think the server did not read my .htaccess file. How do I find out the issue?
Upvotes: 2
Views: 1960
Reputation: 143946
My guess is that your scripts and styles are being linked to via relative URLs. Because the old URL is /cms/content.php
the URI base is /cms/
and your relative links all resolved to be under /cms/
, which I assume is what you want.
However, when you change your links to /cms/content/1234
, the URI base becomes /cms/content/
and all relative links will use this as its base, and since "content" isn't even a real folder, all those links will 404, and you won't load any of your CSS content or scripts.
Either change your links to absolute URLs or specify a URI base in the header of your pages (inside the <head> </head>
tags):
<base href="/cms/" />
Upvotes: 0
Reputation: 2763
You have /cms/
in your URL before the rest, so you need to change RewriteRule
to something like this:
RewriteRule ^cms/([a-z]+)\/([0-9]+)\/?$ content.php?action=$1&id=$2 [NC]
Also, I hope you are aware that .htaccess can not work on some servers (like nginx or some custom ones), and even on Apache servers there can be mod_rewrite
disabled.
Upvotes: 0
Reputation: 24478
You need to make sure to include the subfolder if your htaccess is in the root. Try this rule.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cms/([a-z]+)/([0-9]+)/?$ /cms/content.php?action=$1&id=$2 [NC,L]
Also a blank screen usually means a PHP error.
Upvotes: 0
Reputation: 786081
You need to place this rule in /cms/.htaccess
:
RewriteEngine On
RewriteBase /cms/
RewriteRule ^([a-z]+)/([0-9]+)/?$ content.php?action=$1&id=$2 [NC,L,QSA]
Then you need add this in the <head>
section of your page's HTML: <base href="/" />
so that every relative URL is resolved from that URL and not the current page's relative URL.
Upvotes: 0
Reputation: 1423
RewriteEngine On
RewriteRule ^/cms/([a-z]+)/([0-9]+)$ content.php?action=$1&id=$2 [NC]
Remove escape slashes \
Upvotes: 0