0

I am using mod rewrite for my URL's. I have a form that is submitted through ajax, however the post variables are not being passed. I am trying to post from home.php to new_post.php

Is there a way to exclude the new_post.php file from using the rules below? So that the variables can be passed. I tried using:

RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^new_post.php / [L,R=301]

I am using the following in my htaccess:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Now using:

Options +FollowSymLinks -MultiViews    
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^new_post\.php$ / [L,NC]

I am submitting a form from home.php to new_post.php through AJAX. new_post.php inserts the data into mysql, after the data is inserted, I echo the new url that the user should be redirected to as:

echo "post.php?id=$id";

In AJAX success I use location(data); to redirect the user to the new post.

There are two problems:

The url redirects to an ACCESS FORBIDDEN message from xampp and the post variables are not passed

user3312792
  • 1,101
  • 2
  • 12
  • 27

1 Answers1

0

Have your rules in this order:

Options +FollowSymLinks -MultiViews    
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^post\.php$ / [L,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643