1

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pedram
  • 15,766
  • 10
  • 44
  • 73
  • @anubhava it's in root. have a one 404 error, Failed to load resource: the server responded with a status of 404 (Not Found) --in-- /cms/files/plugin/tinymce/tinymce.min.js – Pedram Mar 09 '15 at 14:08
  • Is `/cms/` a wordpress installation? Does `/cms/` folder also have a .htaccess? – anubhava Mar 09 '15 at 14:13
  • @anubhava no in cms is my own cms. there isn't any htaccess in /cms. in prev answer, about 404 error. it should load .js file from mystie.com/files/plugin/tinymce/tinymce.min.js -- not -- mystie.com/cms/files/plugin/tinymce/tinymce.min.js -- what's the problem? – Pedram Mar 09 '15 at 14:26
  • Added the info on the comments to your question and Improved some formatting and grammar – Fabio Antunes Mar 09 '15 at 14:31
  • ok, thanks for edit. and sorry for my bad english @FabioAntunes – Pedram Mar 09 '15 at 14:35

5 Answers5

0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Forien
  • 2,712
  • 2
  • 13
  • 30
  • still not working.. yes you right but i have checked before on another website in this server. tested on wordpress and other cms with pretty urls plugin. – Pedram Mar 09 '15 at 14:11
0
RewriteEngine On
RewriteRule ^/cms/([a-z]+)/([0-9]+)$ content.php?action=$1&id=$2 [NC]

Remove escape slashes \

MatejG
  • 1,393
  • 1
  • 17
  • 26
0

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/" />
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
0

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.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • this code also not working. i think the problem is something else. – Pedram Mar 09 '15 at 14:42
  • thanks, now i know htaccess working fine. also your answer works perfectly, but css or not loaded, i'm working on it, i think need to change base or src .. thanks for your great help. – Pedram Mar 12 '15 at 07:21
  • it's already have this. but css will redirect. css is in css/style.css but it redirect to cms/style.css, should i change css src to /cms/style/style.css ? – Pedram Mar 12 '15 at 07:35
  • Yes it is always better to use full path like that. If you css/js are in `/cms/` then you need to use: `` in `head` section of HTML. – anubhava Mar 12 '15 at 07:37
0

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.

Panama Jack
  • 24,158
  • 10
  • 63
  • 95