Reputation: 933
I have been working for some time to try and get
website.com/$1/$2/$3
website.com/$1/$2
to produce
website.com/public/index.php?module=$1&controller=$2&action=$3
website.com/public/index.php?controller=$1&action=$2
but I cannot seem to get it working
I am attempting this with two .htaccess files
.htaccess file located in root/
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteRule !^public/ public%{REQUEST_URI} [L]
</IfModule>
.htaccess file located in root/public/
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteRule ^public/([^/]+)/([^/]+)/([^/]+)(/|)$ public/index.php?module=$1&controller=$2&action=$3
RewriteRule ^public/([^/]+)/([^/]+)(/|)$ public/index.php?controller=$1&action=$2
</IfModule>
I currently have it redirecting to the public/ but cannot find a way to change the get variables
Upvotes: 1
Views: 1838
Reputation: 933
I solved it myself with this single .htaccess fine in the root
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ $1.php [L]
RewriteRule !^public/ public%{REQUEST_URI} [L]
RewriteRule ^(.*)/([style|css|js|javascript|images|img|fonts|swf]+)/(.*)$ public/$2/$3 [L]
RewriteRule ^public/([^/]+)/([^/]+)/([^/]+)/?$ public/index.php?module=$1&controller=$2&action=$3 [L]
RewriteRule ^public/([^/]+)/([^/]+)/?$ public/index.php?controller=$1&action=$2 [L]
EDIT:
I have chosen to move my url pacing to my php since htaccess is a nightmere for this sort of thing and If / Else statements are amazing... new code for those of you with similar problem is:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php/$1 [L]
RewriteRule ^(.*)/([style|css|js|javascript|images|img|fonts|swf]+)/(.*)$ public/$2/$3 [L]
ErrorDocument 404 /error404
ErrorDocument 403 /error403
Upvotes: 1
Reputation: 3177
The Tag <IfModule mod_rewrite.c>
only works in the apache-configuration.
In your .htaccess file you have to start with
RewriteEngine On
RewriteBase /
followed by your conditions.
Upvotes: 0
Reputation: 99909
In root/public/.htaccess, matched and rewrote pathes are relative to root/public, so they don't start with public, and you must not try to match ^public:
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/([^/]+)(/|)$ index.php?module=$1&controller=$2&action=$3
RewriteRule ^([^/]+)/([^/]+)(/|)$ index.php?controller=$1&action=$2
The optional slash at the end can be matched with /?
:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?module=$1&controller=$2&action=$3
Upvotes: 0